summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2016-09-10 06:22:09 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2016-09-10 06:22:09 (GMT)
commitbc6262675c70e62ab2d578505e52a409a2c0849f (patch)
tree1a577cef57ce09bcf6b152456a2adb3cc0a124f4 /Lib/test
parent54de2b1edd67ca88c470259d090c8c4cddcadd55 (diff)
downloadcpython-bc6262675c70e62ab2d578505e52a409a2c0849f.zip
cpython-bc6262675c70e62ab2d578505e52a409a2c0849f.tar.gz
cpython-bc6262675c70e62ab2d578505e52a409a2c0849f.tar.bz2
Issue #18401: Fix test_pdb on Windows
* Use "with Popen" to cleanup properly the process * Use support.temp_cwd() to properly change the working directory * Use environ.pop() to cleanup the code
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_pdb.py21
1 files changed, 7 insertions, 14 deletions
diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py
index 2076e2f..74417c1 100644
--- a/Lib/test/test_pdb.py
+++ b/Lib/test/test_pdb.py
@@ -4,7 +4,6 @@ import doctest
import os
import pdb
import sys
-import tempfile
import types
import unittest
import subprocess
@@ -1057,19 +1056,15 @@ class PdbTestCase(unittest.TestCase):
def test_readrc_kwarg(self):
- save_home = os.environ.get('HOME', None)
- save_dir = os.getcwd()
script = textwrap.dedent("""
import pdb; pdb.Pdb(readrc=False).set_trace()
print('hello')
""")
- try:
- if save_home is not None:
- del os.environ['HOME']
- with tempfile.TemporaryDirectory() as dirname:
- os.chdir(dirname)
+ save_home = os.environ.pop('HOME', None)
+ try:
+ with support.temp_cwd():
with open('.pdbrc', 'w') as f:
f.write("invalid\n")
@@ -1083,16 +1078,14 @@ class PdbTestCase(unittest.TestCase):
stdin=subprocess.PIPE,
stderr=subprocess.PIPE,
)
- self.addCleanup(proc.stdout.close)
- self.addCleanup(proc.stderr.close)
- stdout, stderr = proc.communicate(b'q\n')
- self.assertNotIn("NameError: name 'invalid' is not defined",
- stdout.decode())
+ with proc:
+ stdout, stderr = proc.communicate(b'q\n')
+ self.assertNotIn("NameError: name 'invalid' is not defined",
+ stdout.decode())
finally:
if save_home is not None:
os.environ['HOME'] = save_home
- os.chdir(save_dir)
def tearDown(self):
support.unlink(support.TESTFN)