diff options
author | Victor Stinner <vstinner@redhat.com> | 2019-06-03 01:51:43 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-03 01:51:43 (GMT) |
commit | 0025350294959594e7f57aef4fc9579c77a0ed1c (patch) | |
tree | 8fb501ae17c33b278f4a9a2aa38a96b8b5f35164 /Lib/test/test_cprofile.py | |
parent | 13136e83a637a9f1cfbada7e93097005296659b4 (diff) | |
download | cpython-0025350294959594e7f57aef4fc9579c77a0ed1c.zip cpython-0025350294959594e7f57aef4fc9579c77a0ed1c.tar.gz cpython-0025350294959594e7f57aef4fc9579c77a0ed1c.tar.bz2 |
bpo-37069: tests use catch_unraisable_exception() (GH-13762)
Modify test_coroutines, test_cprofile, test_generators, test_raise,
test_ssl and test_yield_from to use
support.catch_unraisable_exception() rather than
support.captured_stderr().
test_thread: remove test_save_exception_state_on_error() which is now
updated. test_unraisable_exception() checks that sys.unraisablehook()
is called to handle _thread.start_new_thread() exception.
test_cprofile now rely on unittest for test discovery: replace
support.run_unittest() with unittest.main().
Diffstat (limited to 'Lib/test/test_cprofile.py')
-rw-r--r-- | Lib/test/test_cprofile.py | 32 |
1 files changed, 12 insertions, 20 deletions
diff --git a/Lib/test/test_cprofile.py b/Lib/test/test_cprofile.py index efcf6bc..5c70037 100644 --- a/Lib/test/test_cprofile.py +++ b/Lib/test/test_cprofile.py @@ -1,13 +1,13 @@ """Test suite for the cProfile module.""" import sys -from test.support import run_unittest, TESTFN, unlink import unittest # rip off all interesting stuff from test_profile import cProfile from test.test_profile import ProfileTest, regenerate_expected_output from test.support.script_helper import assert_python_failure, assert_python_ok +from test import support class CProfileTest(ProfileTest): @@ -18,24 +18,18 @@ class CProfileTest(ProfileTest): def get_expected_output(self): return _ProfileOutput - # Issue 3895. def test_bad_counter_during_dealloc(self): + # bpo-3895 import _lsprof - # Must use a file as StringIO doesn't trigger the bug. - orig_stderr = sys.stderr - try: - with open(TESTFN, 'w') as file: - sys.stderr = file - try: - obj = _lsprof.Profiler(lambda: int) - obj.enable() - obj = _lsprof.Profiler(1) - obj.disable() - obj.clear() - finally: - sys.stderr = orig_stderr - finally: - unlink(TESTFN) + + with support.catch_unraisable_exception() as cm: + obj = _lsprof.Profiler(lambda: int) + obj.enable() + obj = _lsprof.Profiler(1) + obj.disable() + obj.clear() + + self.assertEqual(cm.unraisable.exc_type, TypeError) def test_profile_enable_disable(self): prof = self.profilerclass() @@ -70,12 +64,10 @@ class TestCommandLine(unittest.TestCase): self.assertGreater(rc, 0) self.assertIn(b"option -s: invalid choice: 'demo'", err) -def test_main(): - run_unittest(CProfileTest, TestCommandLine) def main(): if '-r' not in sys.argv: - test_main() + unittest.main() else: regenerate_expected_output(__file__, CProfileTest) |