diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2016-12-31 09:03:13 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2016-12-31 09:03:13 -0500 |
commit | 5d5327ba4c09f65149018c81a7c53ebb0d34acb4 (patch) | |
tree | c9efe0fdf63d4c03fd93e52112ab654644f92cd2 | |
parent | 582d588fc4f02484f1bc568ca6c5178a565af7b0 (diff) | |
download | python-coveragepy-git-5d5327ba4c09f65149018c81a7c53ebb0d34acb4.tar.gz |
Add a test of the atexit/gettrace behavior
-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.""" |