diff options
-rw-r--r-- | tests/test_oddball.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/test_oddball.py b/tests/test_oddball.py index b481131a..68fa7265 100644 --- a/tests/test_oddball.py +++ b/tests/test_oddball.py @@ -5,6 +5,8 @@ import sys +import pytest + import coverage from coverage import env from coverage.files import abs_file @@ -488,6 +490,35 @@ class GettraceTest(CoverageTest): ), ) + @pytest.mark.expensive + def test_atexit_gettrace(self): + # This is not a test of coverage at all, but of our understanding + # of this edge-case behavior in various Pythons. + self.make_file("atexit_gettrace.py", """\ + import atexit, sys + + def trace_function(frame, event, arg): + return trace_function + sys.settrace(trace_function) + + def show_trace_function(): + tfn = sys.gettrace() + if tfn is not None: + tfn = tfn.__name__ + print(tfn) + atexit.register(show_trace_function) + + # This will show what the trace function is at the end of the program. + """) + status, out = self.run_command_status("python atexit_gettrace.py") + self.assertEqual(status, 0) + if env.PYPY: + # PyPy clears the trace function before atexit runs. + self.assertEqual(out, "None\n") + else: + # Other Pythons leave the trace function in place. + self.assertEqual(out, "trace_function\n") + class ExecTest(CoverageTest): """Tests of exec.""" |