You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
test_runpy causes running all Python tests when run directly #75221
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=Nonecreated_at=<Date2017-07-25.16:17:29.593>labels= ['type-bug', 'tests', '3.9', '3.10', '3.11']
title='test_runpy causes running all Python tests when run directly'updated_at=<Date2022-01-16.18:38:48.803>user='https://github.com/serhiy-storchaka'
This is a result of a known quirk in the way sys.path entry execution works: the search for "__main__.py" isn't constrained specifically to sys.path[0].
That's almost entirely a bad thing, but I'd been ignoring it because I hadn't thought of a nice way of fixing it that didn't require some substantial changes to the import system APIs.
However, it just occurred to me that I may have been overcomplicating matters: we don't need to keep runpy from *finding* a __main__.py from outside sys.path[0] in this case, we just need to keep it from *running* it.
That means that after we find the candidate module spec for __main__, we can introduce a new constraint:
It might still be a little fiddly to decide exactly when to enforce the constraint, but it should still be much easier than attempting to constrain the search for the spec directly.
Activity
serhiy-storchaka commentedon Jul 25, 2017
$ ./python Lib/test/test_runpy.py .......................== CPython 3.7.0a0 (heads/master-dirty:39243779f4, Jul 25 2017, 14:32:21) [GCC 6.3.0 20170406] == Linux-4.10.0-28-generic-i686-athlon-with-debian-stretch-sid little-endian == hash algorithm: siphash24 32bit == cwd: /home/serhiy/py/cpython/build/test_python_31873 == CPU count: 2 == encodings: locale=UTF-8, FS=utf-8 Testing with flags: sys.flags(debug=0, inspect=0, interactive=0, optimize=0, dont_write_bytecode=0, no_user_site=0, no_site=0, ignore_environment=0, verbose=0, bytes_warning=0, quiet=0, hash_randomization=1, isolated=0) Run tests sequentially 0:00:00 load avg: 0.85 [ 1/406] test_grammar 0:00:00 load avg: 0.85 [ 2/406] test_opcodes 0:00:00 load avg: 0.85 [ 3/406] test_dict 0:00:01 load avg: 0.85 [ 4/406] test_builtin 0:00:02 load avg: 0.85 [ 5/406] test_exceptions 0:00:02 load avg: 0.85 [ 6/406] test_types ...In isolated mode it runs normally.
Ran 30 tests in 2.776s
OK
serhiy-storchaka commentedon Jul 25, 2017
After commenting out methods test_directory_error, test_zipfile_error and test_main_recursion_error, test_runpy is passed.
ncoghlan commentedon Jul 26, 2017
This is a result of a known quirk in the way sys.path entry execution works: the search for "__main__.py" isn't constrained specifically to sys.path[0].
That's almost entirely a bad thing, but I'd been ignoring it because I hadn't thought of a nice way of fixing it that didn't require some substantial changes to the import system APIs.
However, it just occurred to me that I may have been overcomplicating matters: we don't need to keep runpy from *finding* a __main__.py from outside sys.path[0] in this case, we just need to keep it from *running* it.
That means that after we find the candidate module spec for __main__, we can introduce a new constraint:
It might still be a little fiddly to decide exactly when to enforce the constraint, but it should still be much easier than attempting to constrain the search for the spec directly.
iritkatriel commentedon Jan 16, 2022
Reproduced on 3.11.
Merge branch 'main' into pythongh-75221-runpy-main-search