diff options
author | Mario Corchero <mariocj89@gmail.com> | 2018-02-03 06:40:11 (GMT) |
---|---|---|
committer | Nick Coghlan <ncoghlan@gmail.com> | 2018-02-03 06:40:11 (GMT) |
commit | 38bfa8418f5d39bcc7478b8f7aef4a632c26172e (patch) | |
tree | 33c7f43db19885633bbbc0f66cf46d9c74cb9de3 /Lib/test/test_pdb.py | |
parent | 4e9da0d163731caa79811c723c703ee416c31826 (diff) | |
download | cpython-38bfa8418f5d39bcc7478b8f7aef4a632c26172e.zip cpython-38bfa8418f5d39bcc7478b8f7aef4a632c26172e.tar.gz cpython-38bfa8418f5d39bcc7478b8f7aef4a632c26172e.tar.bz2 |
bpo-32691: Use mod_spec.parent when running modules with pdb (GH-5474)
Previously the module name was used, which broke relative imports when pdb was run against a plain module or submodule.
Diffstat (limited to 'Lib/test/test_pdb.py')
-rw-r--r-- | Lib/test/test_pdb.py | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index 70d8d1d..9aa38e0 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -1447,10 +1447,41 @@ class PdbTestCase(unittest.TestCase): quit """ stdout, _ = self._run_pdb(['-m', self.module_name], commands) - self.assertTrue(any("VAR from module" in l for l in stdout.splitlines())) + self.assertTrue(any("VAR from module" in l for l in stdout.splitlines()), stdout) self.assertTrue(any("VAR from top" in l for l in stdout.splitlines())) self.assertTrue(any("second var" in l for l in stdout.splitlines())) + def test_relative_imports_on_plain_module(self): + # Validates running a plain module. See bpo32691 + self.module_name = 't_main' + support.rmtree(self.module_name) + main_file = self.module_name + '/runme.py' + init_file = self.module_name + '/__init__.py' + module_file = self.module_name + '/module.py' + self.addCleanup(support.rmtree, self.module_name) + os.mkdir(self.module_name) + with open(init_file, 'w') as f: + f.write(textwrap.dedent(""" + top_var = "VAR from top" + """)) + with open(main_file, 'w') as f: + f.write(textwrap.dedent(""" + from . import module + pass # We'll stop here and print the vars + """)) + with open(module_file, 'w') as f: + f.write(textwrap.dedent(""" + var = "VAR from module" + """)) + commands = """ + b 3 + c + p module.var + quit + """ + stdout, _ = self._run_pdb(['-m', self.module_name + '.runme'], commands) + self.assertTrue(any("VAR from module" in l for l in stdout.splitlines()), stdout) + def load_tests(*args): from test import test_pdb |