Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-44461: Check early that a pdb target is valid for execution. #27227

Merged
merged 5 commits into from Jul 28, 2021
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -169,7 +169,11 @@ def code(self):

class ModuleTarget(str):
def check(self):
pass
try:
self._details
except Exception:
traceback.print_exc()
sys.exit(1)

@functools.cached_property
def _details(self):
@@ -1729,6 +1729,20 @@ def test_module_without_a_main(self):
self.assertIn("ImportError: No module named t_main.__main__",
stdout.splitlines())

def test_package_without_a_main(self):
pkg_name = 't_pkg'
module_name = 't_main'
os_helper.rmtree(pkg_name)
modpath = pkg_name + '/' + module_name
os.makedirs(modpath)
with open(modpath + '/__init__.py', 'w') as f:
pass
self.addCleanup(os_helper.rmtree, pkg_name)
stdout, stderr = self._run_pdb(['-m', modpath.replace('/', '.')], "")
self.assertIn(
"'t_pkg.t_main' is a package and cannot be directly executed",
stdout)

def test_blocks_at_first_code_line(self):
script = """
#This is a comment, on line 2
@@ -0,0 +1 @@
Fix bug with :mod:`pdb`'s handling of import error due to a package which does not have a ``__main__`` module