You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
If coverage.py with the sys.monitoring API is used at the same time as another tool is using it to collect coverage, an unhandled exception will be raised:
Yeah, the issue is that dd-trace-py allocates the tool earlier, so the exception is raised by coverage in a later pytest hook. I've tried splitting in two phases dd-trace-py code, allowing coverage to start in the middle, but it breaks the functionality.
Maybe the solution is for dd-trace-py to use a different tool id altogether, but this is for an internal coverage-based tool, so registering as a coverage tool was the natural move.
My hunch was that coverage could capture the ValueError, log a warning or similar, and let the pytest process continue, but not sure how this is expected to be handled to be honest.
My hunch was that coverage could capture the ValueError, log a warning or similar, and let the pytest process continue, but not sure how this is expected to be handled to be honest.
Maybe we need to take a step back: why are both tools running at once? Do you want them to both capture data?
Sorry Ned, this was definitely missing some context.
First of all, allow me to thank you for the great job you're doing with coverage.py.
The issue here is when pytest is run with both plugins pytest-cov and dd-trace-py (this latter one under certain config), that collect coverage for different purposes.
The use case is as follows: pytest-cov would keep track of coverage at session level, and report it as usual. Simultaneously, dd-trace-py may be collecting coverage on a per-test basis, for a feature of selective testing called Test Impact Analysis, that will allow test skipping in subsequent test executions if the code changes and the specific test to be executed are unrelated.
In short, I think dd-trace-py could use a different tool id to avoid collisions, but I also think that this exception should be handled, allowing test execution to take place. Probably the place to handle this exception is pytest-cov instead of coverage.py, although raising a more specific exception may be useful for pytest-cov.
Activity
nedbat commentedon Jun 5, 2026
What is the other tool?
devdanzin commentedon Jun 5, 2026
It seems there's one called "scalpel":
https://github.com/fun-altF4/scalpel/blob/072e5d4d4ffafd8c6029ffdef15ce0b0117a1825/probes/python/probe.py#L222-L230
And SlipCover too, but it checks for conflicts:
https://github.com/plasma-umass/slipcover/blob/dd9fdbb6c85896b6fd2c29f8d7d87559b94de793/src/slipcover/slipcover.py#L382-L386
gnufede commentedon Jun 5, 2026
dd-trace-py used like
pytest --ddtracein my casenedbat commentedon Jun 5, 2026
What would you like coverage to do? Raise a different exception? dd-trace-py does this:
nedbat commentedon Jun 5, 2026
In retrospect, the sys.monitoring tool-id scheme seems too simplistic. Why pre-allocate an ID to coverage if more than one tool might want to use it?
gnufede commentedon Jun 5, 2026
Yeah, the issue is that dd-trace-py allocates the tool earlier, so the exception is raised by coverage in a later pytest hook. I've tried splitting in two phases dd-trace-py code, allowing coverage to start in the middle, but it breaks the functionality.
Maybe the solution is for dd-trace-py to use a different tool id altogether, but this is for an internal coverage-based tool, so registering as a coverage tool was the natural move.
My hunch was that coverage could capture the ValueError, log a warning or similar, and let the pytest process continue, but not sure how this is expected to be handled to be honest.
nedbat commentedon Jun 5, 2026
Maybe we need to take a step back: why are both tools running at once? Do you want them to both capture data?
gnufede commentedon Jun 8, 2026
Sorry Ned, this was definitely missing some context.
First of all, allow me to thank you for the great job you're doing with
coverage.py.The issue here is when
pytestis run with both pluginspytest-covanddd-trace-py(this latter one under certain config), that collect coverage for different purposes.The use case is as follows:
pytest-covwould keep track of coverage at session level, and report it as usual. Simultaneously,dd-trace-pymay be collecting coverage on a per-test basis, for a feature of selective testing called Test Impact Analysis, that will allow test skipping in subsequent test executions if the code changes and the specific test to be executed are unrelated.In short, I think
dd-trace-pycould use a different tool id to avoid collisions, but I also think that this exception should be handled, allowing test execution to take place. Probably the place to handle this exception ispytest-covinstead ofcoverage.py, although raising a more specific exception may be useful forpytest-cov.fix: find a usable sys.monitoring toolid instead of assuming COVERAGE…
nedbat commentedon Jun 8, 2026
In commit 4b0fc85 I've changed the logic to search for an unused tool id, fixing this.
nedbat commentedon Jun 20, 2026
This is now released as part of coverage 7.14.2.