diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2011-06-29 22:00:45 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2011-06-29 22:00:45 (GMT) |
commit | 7f86811d55a7a15cb4f29f9fad458aecaf2161d3 (patch) | |
tree | be3c1627314156d8d65bce83a30bbecf52ac5475 /Lib/test/test_cprofile.py | |
parent | 0aafa4f1e2facddf4aa2a5ac52ecd73fdf751580 (diff) | |
download | cpython-7f86811d55a7a15cb4f29f9fad458aecaf2161d3.zip cpython-7f86811d55a7a15cb4f29f9fad458aecaf2161d3.tar.gz cpython-7f86811d55a7a15cb4f29f9fad458aecaf2161d3.tar.bz2 |
Issue #12400: test_cprofile now restores correctly the previous sys.stderr
Copy sys.stderr before replacing it, instead of using sys.__stderr__
Diffstat (limited to 'Lib/test/test_cprofile.py')
-rw-r--r-- | Lib/test/test_cprofile.py | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/Lib/test/test_cprofile.py b/Lib/test/test_cprofile.py index ae17c2b..5676668 100644 --- a/Lib/test/test_cprofile.py +++ b/Lib/test/test_cprofile.py @@ -18,16 +18,19 @@ class CProfileTest(ProfileTest): def test_bad_counter_during_dealloc(self): import _lsprof # Must use a file as StringIO doesn't trigger the bug. - with open(TESTFN, 'w') as file: - sys.stderr = file - try: - obj = _lsprof.Profiler(lambda: int) - obj.enable() - obj = _lsprof.Profiler(1) - obj.disable() - finally: - sys.stderr = sys.__stderr__ - unlink(TESTFN) + 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() + finally: + sys.stderr = orig_stderr + finally: + unlink(TESTFN) def test_main(): |