Open himperion92 opened 5 years ago
Can you make a reproducer? I can't tell what the problem is from just this. It looks like in the xml the packages were merged and the root disappeared. Maybe @nedbat has seen this problem before but I haven't and need a reproducer example.
@ionelmc here you have attached a project that will cause this behavior. Just download it and execute the following command with pytest-4.4.1 and pytest-cov-2.7.1:
pytest -v --junitxml unittests.xml --cov=Module1 --cov=Module2 --cov=Module3 --cov-config .coveragerc --cov-report xml --cov-report term
Just an idea/remark: try to use include = Module1, Module2, Module3
in the coverage config, and specify --cov
only (without sources).
Also try to figure out how coverage.py itself handles it, e.g. look at coverage report
afterwards, and try using coverage run -m pytest …
.
Hello! I face same trouble (in CI pipeline between atlassian bamboo and sonarqube) and spent many hours for debug. Finally i googled this issue, but as i can understand, here is no clear explanation. So. Finally i found out following: if you have similar project structure (like described in issue), use whole folder, not apps/modules. For example, if you have module1, module2, module3 and use "--cov module1 --cov module2 --cov module3", just replace it with "--cov ." and add some omit/restictions to skip necessary files. This helps me (sonarqube with previous coverage report show coverage at 46% for our project, now it shows real 97% (as you understands, we often repeat names in different packages - like helpers.py and other))
Explanation: as i understands (i may misunderstood logic), coverage get files from folders ("--cov module1 --cov module2 --cov module3") and use paths as keys, so if you have same names, they obiously will be overriden in final report file, because it's just flat list, without parent folders (parent folder can be found only at the top of report file (cubertura at least)).
It seems very obvious for expirienced users of coverage, but i was not like them (though i spent many years in it industry and many years i generated those reports, but faced this issue first time), so i decided to save time for any user who gets here
Perhaps document this somewhere?
This issue appears when there are some modules with the same name but in different namespaces within the same project or if you have code in init files. I have this dummy project with the following structure:
If I run the following command:
pytest -v --junitxml unittests.xml --cov=Module1 --cov=Module2 --cov=Module3 --cov-config .coveragerc --cov-report xml --cov-report term
Although the "term" Cobertura report shows correctly the coverage of all the modules:
The coverage.xml file includes only the coverage for two files:
As you can see, the report only shows one "Functionality.py" coverage and on "init.py" where it should show all of them. If you try to parse this log with Jenkins using the Cobertura plugin, it will only show one file for every group of files that share name (and only one init file as well).
This issue was not reproduced in version pytest-cov==2.2.0, where it would treat the coverage of each file separately in the xml report even if the names where the same.