New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Report correct coverage.py data for tests that invoke subprocesses #56187
Comments
http://nedbatchelder.com/code/coverage/subprocess.html describes how to instruct a test suite that spawns subprocesses to correctly report coverage data for code covered only in those subprocesses. regrtest currently doesn't do this, so modules that use subprocesses to run their tests may report inaccurate coverage numbers when using this tool (as recommended in the devguide). (Those numbers are irredeemably inaccurate when it comes to regrtest's own coverage assessment) It may be better to build explicit invocation of coverage.py when regrtest is run under coverage.py into test.script_helper rather than trying to use the implicit mechanism though (as neither sitecustomize nor a .pth file are particularly good ideas when running Python's own test suite). |
Let me know if I can help. |
I found the regrtest wasn't displaying correct coverage for when the code is executed from call What should be the ideal situation for this? I request any core-developer to guide on this. I am interested in doing some more research on this issue. Thanks! |
As a starting point, I'd suggest looking at what can be achieved without making any changes to CPython or its test suite:
There are cases that won't cover (like subprocesses with a custom environment), but it will provide a starting point for the tests that just pass the current environment through, and will also provide a way to notify test.support.script_helper of the expected value of COVERAGE_PROCESS_START in the future. |
To be more specific regarding $ echo "print('Hello from sitecustomize.py')" > Lib/sitecustomize.py
$ ./python -c "print('Hello from command line')"
Hello from sitecustomize.py
Hello from command line Since we only need these instructions to work for a local checkout, we can rely on the It means we'll still miss coverage results from subprocess tests run in isolated mode or with site.py processing disabled, but those are both relatively rare and involve *not* running code that is normally run, so shouldn't impact the aggregate coverage results. |
There's also what changes might occur in the coverage results when we start using fullcoverage: python/core-workflow#18 |
I learned a few thing trying to make this work. One is that the COVERAGE_PROCESS_START does need to point to an actual .ini file (which includes an empty file). Two, https://bitbucket.org/ned/coveragepy/src/63dfe482a849e9cb0b82214242315a806a6a3d53/coverage/control.py?at=default&fileviewer=file-view-default#control.py-1265 shows that stdlib coverage is left off by this, so even if you do turn on tracing in a subprocess, it will still ignore the stdlib. That means the coverage config file must turn on stdlib coverage in order or it to be picked up in the subprocesses. Three, you need to run When I have time I'll make a PR to test if this change actually helps speed things up. |
Just an FYI that I have never managed to make this work. |
Whoever takes this up next: let me know if I can help. |
So there was progress here. Ever since we switched to sys.monitoring, the default |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: