Issue #14285: Do not catch ImportError from __init__.py in runpy
Initialize package before calling get_loader() for __main__, so that we do
not incorrectly handle ImportError from __init__.py. When runpy is used from
the Python CLI, use an internal exception rather than ImportError, to avoid
catching an unexpected ImportError.
Also simplify message formatting: str() is redundant with %s.
Also fix test_dash_m_error_code_is_one() in test_cmd_line_script, which was
failing because the test package was not in the current directlry, rather
the desired ValueError.
diff --git a/Lib/test/script_helper.py b/Lib/test/script_helper.py
index 7f7c70e..6be47bd 100644
--- a/Lib/test/script_helper.py
+++ b/Lib/test/script_helper.py
@@ -134,9 +134,9 @@
# zip_file.close()
return zip_name, os.path.join(zip_name, name_in_zip)
-def make_pkg(pkg_dir):
+def make_pkg(pkg_dir, init_source=''):
os.mkdir(pkg_dir)
- make_script(pkg_dir, '__init__', '')
+ make_script(pkg_dir, '__init__', init_source)
def make_zip_pkg(zip_dir, zip_basename, pkg_name, script_basename,
source, depth=1, compiled=False):