[Python-checkins] cpython: Issue #18401: Fix test_pdb on Windows

victor.stinner python-checkins at python.org
Sat Sep 10 02:22:30 EDT 2016


https://hg.python.org/cpython/rev/5aa77974dd56
changeset: 103555:5aa77974dd56
user: Victor Stinner <victor.stinner at gmail.com>
date: Fri Sep 09 23:22:09 2016 -0700
summary:
 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
files:
 Lib/test/test_pdb.py | 21 +++++++--------------
 1 files changed, 7 insertions(+), 14 deletions(-)
diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py
--- a/Lib/test/test_pdb.py
+++ b/Lib/test/test_pdb.py
@@ -4,7 +4,6 @@
 import os
 import pdb
 import sys
-import tempfile
 import types
 import unittest
 import subprocess
@@ -1057,19 +1056,15 @@
 
 
 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')
 """)
+
+ save_home = os.environ.pop('HOME', None)
 try:
- if save_home is not None:
- del os.environ['HOME']
-
- with tempfile.TemporaryDirectory() as dirname:
- os.chdir(dirname)
+ with support.temp_cwd():
 with open('.pdbrc', 'w') as f:
 f.write("invalid\n")
 
@@ -1083,16 +1078,14 @@
 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)
-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /