The following code causes an issue for me where I have changed away from the coverage tracer to a tracer of my own devising, but the coverage CTracer mysteriously reappears.
import sys def tracer(frame, event, arg): return tracer def begin(): sys.settrace(tracer) def collect(): t = sys.gettrace() assert t is tracer, t def test_unsets_trace(): begin() collect() if __name__ == '__main__': test_unsets_trace()
Running the above code under 'python -m coverage run test_coverage_unset_trace.py' (or whatever you call the file) under Python 3.4.3 or 3.5.0 with coverage 4.0.1 produces the following error for me:
Traceback (most recent call last): File "test_coverage_regression.py", line 23, in <module> test_unsets_trace() File "test_coverage_regression.py", line 19, in test_unsets_trace collect() File "test_coverage_regression.py", line 14, in collect assert t is tracer, t AssertionError: <coverage.CTracer object at 0x7fbdfa585a40>
Note: I do not see this issue on Coverage 4.0.0, or on Python 2.7 running 4.0.1. This seems to be specifically 4.0.1 and Python 3 together that cause the problem.
I originally believed this to be related to the fix for https://bitbucket.org/ned/coveragepy/issues/397/stopping-and-resuming-coverage-with, but I can't see why the tracer object would be running via settrace at this point rather than C level tracing, so this might be a red herring.
If I run this with --timid I get the "trace function changed" warning but do not see this problem.