[Python-checkins] cpython: Issue #18401: Fix test_pdb if $HOME is not set

victor.stinner python-checkins at python.org
Sat Sep 10 01:57:04 EDT 2016


https://hg.python.org/cpython/rev/09c730db1aac
changeset:   103553:09c730db1aac
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Fri Sep 09 22:56:54 2016 -0700
summary:
  Issue #18401: Fix test_pdb if $HOME is not set

HOME is not set on Windows for example.

Use also textwrap.dedent() for the script.

files:
  Lib/test/test_pdb.py |  16 ++++++++++------
  1 files changed, 10 insertions(+), 6 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
@@ -1057,14 +1057,17 @@
 
 
     def test_readrc_kwarg(self):
-        save_home = os.environ['HOME']
+        save_home = os.environ.get('HOME', None)
         save_dir = os.getcwd()
-        script = """import pdb; pdb.Pdb(readrc=False).set_trace()
+        script = textwrap.dedent("""
+            import pdb; pdb.Pdb(readrc=False).set_trace()
 
-print('hello')
-"""
-        del os.environ['HOME']
+            print('hello')
+        """)
         try:
+            if save_home is not None:
+                del os.environ['HOME']
+
             with tempfile.TemporaryDirectory() as dirname:
                 os.chdir(dirname)
                 with open('.pdbrc', 'w') as f:
@@ -1087,7 +1090,8 @@
                               stdout.decode())
 
         finally:
-            os.environ['HOME'] = save_home
+            if save_home is not None:
+                os.environ['HOME'] = save_home
             os.chdir(save_dir)
 
     def tearDown(self):

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list