Commit 7f86811d authored by Victor Stinner's avatar Victor Stinner

Issue #12400: test_cprofile now restores correctly the previous sys.stderr

Copy sys.stderr before replacing it, instead of using sys.__stderr__
parent 0aafa4f1
...@@ -18,16 +18,19 @@ class CProfileTest(ProfileTest): ...@@ -18,16 +18,19 @@ class CProfileTest(ProfileTest):
def test_bad_counter_during_dealloc(self): def test_bad_counter_during_dealloc(self):
import _lsprof import _lsprof
# Must use a file as StringIO doesn't trigger the bug. # Must use a file as StringIO doesn't trigger the bug.
with open(TESTFN, 'w') as file: orig_stderr = sys.stderr
sys.stderr = file try:
try: with open(TESTFN, 'w') as file:
obj = _lsprof.Profiler(lambda: int) sys.stderr = file
obj.enable() try:
obj = _lsprof.Profiler(1) obj = _lsprof.Profiler(lambda: int)
obj.disable() obj.enable()
finally: obj = _lsprof.Profiler(1)
sys.stderr = sys.__stderr__ obj.disable()
unlink(TESTFN) finally:
sys.stderr = orig_stderr
finally:
unlink(TESTFN)
def test_main(): def test_main():
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment