summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2016-09-10 05:56:54 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2016-09-10 05:56:54 (GMT)
commit11ea04491df185c94c12531c6dba6d46fbcb0ad9 (patch)
tree79f59f9c13f3af444ec31c010e65210e5a02f141
parent2eb6eca3e5118009b6b74b444d73aa377fb44098 (diff)
downloadcpython-11ea04491df185c94c12531c6dba6d46fbcb0ad9.zip
cpython-11ea04491df185c94c12531c6dba6d46fbcb0ad9.tar.gz
cpython-11ea04491df185c94c12531c6dba6d46fbcb0ad9.tar.bz2
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.
-rw-r--r--Lib/test/test_pdb.py16
1 files changed, 10 insertions, 6 deletions
diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py
index c39cc97..2076e2f 100644
--- a/Lib/test/test_pdb.py
+++ b/Lib/test/test_pdb.py
@@ -1057,14 +1057,17 @@ class PdbTestCase(unittest.TestCase):
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 @@ print('hello')
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):