Hi,
I’m trying to integrate my python project with sonarqube, I manage to get it working but, i have a problem with the test file. Basically they are show as not covered properly in the sonar console.
My question is: How can i exclude the test files from the files to cover bucket?
I tried a couple of configuration, but so far no luck. If i put the test file in the excluded list, i get 0% coverage on all the project files. I get the same results if i exclude the test files from the sources or from the test coverage.
Any idea how i can exclude the tests files from coverage?
So everything under that directory is treated as a source file & thus in need of coverage. You can remedy this with a more selective definition of your source file locations
I guess you’ve got your test files jumbled into the same directory as your source files? If so, that’s the root of the problem. You’ve said “everything in the server directory is a source file” and SonarQube takes you at your word.
If you don’t want to sort things into subdirectories (I’m not actually a fan of changing the project to make a tool happy) you might be able to work through this with exclusions. I don’t normally suggest combining inclusions and exclusions (gets terribly confusing) but that might be what you need here:
No, source and test files are in separate folders. You can see that in the snapshot that I’ve attached.
The sources are under /server/bolt while the tests are under /server/tests.
I will try to add sonar source and sonar tests to see if that helps
In the sonar console the tests files are still showing as uncovered files, and this time the covu file doesn’t show up on the sonar console either. So i see 0% coverage.
In the coverage report you attached it seems like there are also test files listed there.
For example I can see server/tests/api/qws/projects_test.py with its absolute path.
Can you please make sure they don’t show up in the coverage report? You can have a look at our guide about generating coverage report here
If you still encounter problems, can you please attach the analysis logs?
Note that for quicker turnaround, I’ve reduced the scope of the tests to bolt/admin source folder only. For this particular run, sonar shows 0.0% coverage
20:17:10.991 ERROR: Cannot resolve the file path '/builds/core-tech/tools/nlu/mix-nlu-middleware/server/routing.py' of the coverage report, the file does not exist in all <source>.
20:17:10.998 ERROR: Cannot resolve 27 file paths, ignoring coverage measures for those files
Could you please double check that filepaths reported in the coverage file are correct and exist?