if modspec is None:
# simple script
return _os.path.basename(arg0)
+ if modspec.name != '__main__' and arg0 != modspec.origin:
+ # named module executed as main without altering sys.argv[0]
+ return _os.path.basename(arg0)
py = _os.path.basename(_sys.executable)
if modspec.name != '__main__':
# imported module or package
def test_module_compiled(self):
self.test_module(compiled=True)
+ def test_module_as_main_without_altering_argv(self):
+ basename = 'module' + os_helper.FS_NONASCII
+ modulename = f'{self.dirname}.{basename}'
+ self.make_script(self.dirname, basename)
+ runner_source = textwrap.dedent(f'''\
+ import runpy
+ runpy._run_module_as_main({modulename!r}, alter_argv=False)
+ ''')
+ runner = script_helper.make_script(
+ self.dirname, 'runner', runner_source)
+ self.check_usage(os.path.basename(runner), runner,
+ PYTHONPATH=os.curdir)
+
def test_package(self, compiled=False):
basename = 'subpackage' + os_helper.FS_NONASCII
packagename = f'{self.dirname}.{basename}'