[issue16737] Different behaviours in script run directly and via runpy.run_module

Isaiah Peng report at bugs.python.org
Thu Oct 26 09:43:11 EDT 2017


Isaiah Peng <issaria at gmail.com> added the comment:

Not sure if it's stated before, this difference of behavior also has other effects, e.g.

$ python -m test.test_traceback

# Ran 61 tests in 0.449s
# FAILED (failures=5)

This is because the loader associated with the module get confused, it loaded the original module as the proper module and then the module changed name to __main__ but the loader is still associated with the old module name, so call to `get_source` fails.

$ cat > test_m.py
print(__loader__.get_source(__name__))

$ python -m test_m

# ImportError: loader for test_m cannot handle __main__

----------
nosy: +isaiah

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue16737>
_______________________________________


More information about the Python-bugs-list mailing list