Open apatanwal-eightfold opened 1 year ago
There's a lot of complexity here. There's no good answer to when coverage might skip lines. It could be that you are losing data when combining files? Other than that, I don't know what could be happening. If you can give me a way to run your test suite, I might be able to find out more.
@nedbat Thanks for the reply. Please help me with these questions.
I also performed a test in which i ran pytest over our codebase in the way or CI framework does and i could see that the result was different everytime.
Run Total Covered %
1 371730 113343 70
2 371730 113097 70
3 371730 113120 70
Have you tried running coverage html
for each run, and comparing the reports, to help drill down to the files / lines where the coverage differences are? Or have you looked into the coverage debug options?
@Zeckie Thanks for the insights, I compared the results and looks like there are some blocks which are not getting hit, most probably because redis cache is not mocked in few tests. I tested the result with coveragepy using parallel mode and disabling cache and was able to get consistent result for few directories. Although using pytest-cov still gave inconsistencies.
Do we know why --append is disabled for parallel mode in coveragepy? Can it be the reason for inconsistency in pytest-cov given i am using --cov-append.
If the problem only happens when using pytest-cov, you should report an error to them: https://github.com/pytest-dev/pytest-cov
Describe the bug We have recently introduced Coverage into our codebase as a means to measure test coverage and observed that that module intermittently misses recording few lines getting touched when run against our test suite. This happens sporadically and we could not identify the cause of this behavior. We believe we are using the tool properly and with the right concurrency inputs. Requesting any pointers on when would such a case happen and any clues on to debug such scenarios.
Following is a summary of how we are using Coverage in our code base:
We run pytest in our codebase by dividing directories among workers. So each worker runs pytest and calculates coverage for the directories assigned to it. There are times when coverage fails to hit lines in a module for which test is ran (we can see from the logs that the test which covers those line was ran). The above in scenario occurs for about 2% of the time.
How do we divide directories among workers? We use Pool from mulitprocessing module in python
multiprocessing.dummy import Pool
So each thread in the pool will run pytest seperately using the subprocess module.
To Reproduce As noted above the problem is not reproducible, It happens intermittently.
Command used
We have the .coveragerc in {cov_directory}/
.coveragerc
What version of Python are you using? -> Python 3.8.11
What version of coverage.py shows the problem?
What versions of what packages do you have installed?
Additional context Each thread in the pool is given a unique 'COVERAGE_FILE' environment variable so that the coverage binaries do not collide.
Also we are using --cov-append which should aggregate the results