summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2016-12-31 09:03:13 -0500
committerNed Batchelder <ned@nedbatchelder.com>2016-12-31 09:03:13 -0500
commit77517450f7164ab471aad3c8776879306bc33787 (patch)
treee9686fbae8fe03a742d26662db70685c6d96ae9c /tests
parent9392e0b0cfa77dce43e8b984985ca38d2de0ffe0 (diff)
downloadpython-coveragepy-77517450f7164ab471aad3c8776879306bc33787.tar.gz
Add a test of the atexit/gettrace behavior
Diffstat (limited to 'tests')
-rw-r--r--tests/test_oddball.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/test_oddball.py b/tests/test_oddball.py
index b481131..68fa726 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."""