I am trying to implement code coverage in the sonar cloud using GitHub actions.
It shows it is integrated, But coverage is 0.0%
From the Analysis details, I found two warnings.
Could not find ref 'main' in refs/heads, refs/remotes/upstream or refs/remotes/origin. You may see unexpected issues and changes. Please make sure to fetch this ref before pull request analysis.
and
The following error(s) occurred while trying to import coverage report:
Cannot resolve 63 file paths, ignoring coverage measures for those files%nCannot
resolve the file path 'src/adapters/__init__.py' of the coverage report, ambiguity,
the file exists in several 'source'.
The GitHub action is
- name: Run tests
run: poetry run pytest tests/unit tests/integration --cov-report=xml --cov-branch --cov=adapters --cov=domain --cov=entrypoints --cov=ports --cov=schemas --cov=service_layer --cov=utils
Sonar properties are
sonar.python.coverage.reportPaths=coverage.xml
sonar.sources=src
sonar.tests=tests
Apologies, If I miss any important details
Related
I am trying to integrate pylint results with SonarQube.
To generate a report I use
pylint ./console/**/*.py --exit-zero --rcfile=.pylintrc > pylint-report.out
In sonar-project.properties I have:
sonar.python.pylint.reportPaths=pylint-report.out
(I tried sonar.python.pylint.reportPath=pylint-report.out also, as I saw some examples on the Internet with such a property).
Unfortunately, the sonar-scanner seems to ignore this setting.
I see no logs about pylint except:
10:56:18.516 DEBUG: 'PylintSensor' skipped because there is no related rule activated in the quality profile
10:56:18.517 DEBUG: 'PylintImportSensor' skipped because there is no related rule activated in the quality profile
But, as I understand this is not important if I generate a report on my own. Am I wrong?
What is a kind of surprise to me is there is no related log. For bandit result, for example, I get logs:
10:56:27.657 INFO: Sensor Import of Bandit issues [python]
10:56:27.658 INFO: Importing /home/gitlab-runner/builds/abcd/0/project/bandit-report.out
With the file or not a log entry is generated that the sonnar-scaner at least tried to read the result. With pylint - nothing :(.
I am using SonarScanner 4.6.0.2311.
SonarServer is Version 8.3.1 (build 34397)
And I use default ruleset from the sonar.
Thanks for any help! :)
The reason was the version of sonarcube server.
After upgrading to 8.6.1 the issue was gone.
Since somebody have to still use version 8.3 of Sonar, you have to setup following in order sonar import your pylint report:
I unit testing python code and running command pytest --cov, test is running fine but coverage is not getting displayed and error is
INTERNALERROR>raise CoverageException("Couldn't use data file {!r}:{}".format(self.filename, msg))
INTERNALERROR> coverage.misc.CoverageException: Couldn't use data file'C:\\Users\\Desktop\\Pytest\\.coverage': Safety level may not be changed inside a transaction
Need help with this problem?
This has been mentioned a few times in the coverage.py issues, and the eventual discovery was that it's a bug in Python 3.6.0, but if you use 3.6.1 or later, you will be fine.
If that doesn't cover your case, feel free to open an issue with details of how to reproduce.
Could be related to https://github.com/nedbat/coveragepy/issues/883#issuecomment-650562896 if you're using multiple pytests in parallel, in which case specifying a distinct coverage file for each run fixes it, like:
export COVERAGE_FILE=.coverage.SOMETHING_SPECIFIC_FOR_EACH_RUN
Use coverage==6.3.1
This works for me
Link to certain version https://pypi.org/project/coverage/6.3.1/
I have Python bdd tests in Behave. Using version 1.2.6
The issue I'm facing is that Allure-behave reports failed suits as "Passed", even if it does show a failed step, and report it as such.
I have a behave.ini in my features folder with:
[behave.formatters]
allure = allure_behave.formatter:AllureFormatter
I run my tests with:
behave -f allure_behave.formatter:AllureFormatter -o allure-results
I do see that the result files being created by allure-behave does say the suits has passed, and is then in turn reported as such on the Allure UI
Did I mis something while setting-up/running tests?
Maybe add something to the "after_scenario" method?
Already fixed in 2.3.3b1
Feel free to create issues in our repo
I'm a complete new starter when it comes to writing python unittests and I know it's far far better and easier to write the tests before the code but I thought I'd start by contributing to a github project and fixing a few small issues and giving it a go.
One issue I was fixing was that if a argument wasn't given to an method, it would actually remove the argument on the server. I should mention that this project is a client for a REST API. This was easy enough to fix but I thought it would be good to write a test for it.
The code of the broken method is included within a class:
def edit_device(self, device, nickname=None, model=None, manufacturer=None):
data = {"nickname": nickname}
iden = device.device_iden
r = self._session.post("{}/{}".format(self.DEVICES_URL, iden), data=json.dumps(data))
I then was going to use Mock to mock the responses of the REST API using their documentation as the guide (it includes example responses).
The issue I am having is I have written my test as:
#mock.patch('pushbullet.pushbullet.requests.Session.get', side_effect=mocked_requests_get)
#mock.patch('pushbullet.pushbullet.requests.Session.post', side_effect=mocked_requests_post)
class TestPushbullet(object):
def test_edit_device_without_nickname(self, mock_get, mock_post):
pb = pushbullet.Pushbullet("API_KEY")
device = pb.devices[0]
new_device = pb.edit_device(device)
assert new_device.nickname == device.nickname
This seems to work correctly, the methods mocked_requests_get and mocked_requests_post get called. If I run this test within eclipse PyDev using pyUnit to run the pytest - it fails, as I expect. If I run the tests using nose it also fails, again perfect. If I run the test using py.test on the command line, it passes.
If I use the pytest.set_trace() as the first line in mocked_requests_post I can print args and it shows that the nickname is in fact not None and still set to what it is on the server (i.e. device.nickname so the assertion passes)
I can't for the life of me work out why py.test is not picking up the change in json from the self._session.post. If I change the iden in the URL format, it does indeed pick up that change, however changing the data body it does not.
Am I doing something intrinsically wrong? I can't see why py.test would pass and nose would fail on the same code.
EDIT: on the command line I'm running py.test path/to/single_test_file.py and the test file has only the single test method I've pasted above.
Finally worked it out, I must have installed the client package into python previous to deciding to write the tests. It looks like the command line py.test was therefore reading the client package from the true source (via pip install) whereas the IDE was reading it from the development package I had in eclipse.
Solution is to remove the package: pip uninstall <package>
Reinstall the development package: pip install -e . (when in the root development directory)
I use paver to run pylint as a task. In my rcfile(pylintrc) I have configured pylint to report only errors by setting errors-only=yes.
But I like to run paver pylint task with a verbose option to get it to report non-errors as well. How can I run pylint overriding the errors-only=yes setting?
Running with --errors-only=no gives an exception indicating that the --errors-only cannot be given a value. --enable=all also does not work.
This is an unexpected restriction that deserve an issue on the pylint's tracker (https://bitbucket.org/logilab/pylint/issues).
Though to get it works properly in your case, I would use a custom rc file for the task that wouldn't be used in my daily usage, eg pylint --rcfile=task.pylinrc ...