summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_regrtest.py
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2019-06-12 23:09:04 (GMT)
committerGitHub <noreply@github.com>2019-06-12 23:09:04 (GMT)
commit95f61c8b1619e736bd5e29a0da0183234634b6e8 (patch)
tree6d70a71d5e9538ab70d9039eabf64315409e939d /Lib/test/test_regrtest.py
parent913fa1c8245d1cde6edb4254f4fb965cc91786ef (diff)
downloadcpython-95f61c8b1619e736bd5e29a0da0183234634b6e8.zip
cpython-95f61c8b1619e736bd5e29a0da0183234634b6e8.tar.gz
cpython-95f61c8b1619e736bd5e29a0da0183234634b6e8.tar.bz2
bpo-37069: regrtest uses sys.unraisablehook (GH-13759)
regrtest now uses sys.unraisablehook() to mark a test as "environment altered" (ENV_CHANGED) if it emits an "unraisable exception". Moreover, regrtest logs a warning in this case. Use "python3 -m test --fail-env-changed" to catch unraisable exceptions in tests.
Diffstat (limited to 'Lib/test/test_regrtest.py')
-rw-r--r--Lib/test/test_regrtest.py30
1 files changed, 29 insertions, 1 deletions
diff --git a/Lib/test/test_regrtest.py b/Lib/test/test_regrtest.py
index b616e89..904b326 100644
--- a/Lib/test/test_regrtest.py
+++ b/Lib/test/test_regrtest.py
@@ -499,7 +499,7 @@ class BaseTestCase(unittest.TestCase):
if not input:
input = ''
if 'stderr' not in kw:
- kw['stderr'] = subprocess.PIPE
+ kw['stderr'] = subprocess.STDOUT
proc = subprocess.run(args,
universal_newlines=True,
input=input,
@@ -1124,6 +1124,34 @@ class ArgsTestCase(BaseTestCase):
env_changed=[testname],
fail_env_changed=True)
+ def test_unraisable_exc(self):
+ # --fail-env-changed must catch unraisable exception
+ code = textwrap.dedent(r"""
+ import unittest
+ import weakref
+
+ class MyObject:
+ pass
+
+ def weakref_callback(obj):
+ raise Exception("weakref callback bug")
+
+ class Tests(unittest.TestCase):
+ def test_unraisable_exc(self):
+ obj = MyObject()
+ ref = weakref.ref(obj, weakref_callback)
+ # call weakref_callback() which logs
+ # an unraisable exception
+ obj = None
+ """)
+ testname = self.create_test(code=code)
+
+ output = self.run_tests("--fail-env-changed", "-v", testname, exitcode=3)
+ self.check_executed_tests(output, [testname],
+ env_changed=[testname],
+ fail_env_changed=True)
+ self.assertIn("Warning -- Unraisable exception", output)
+
class TestUtils(unittest.TestCase):
def test_format_duration(self):