-
-
Notifications
You must be signed in to change notification settings - Fork 30k
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-37473: Don't import importlib ASAP in tests #14661
Conversation
@brettcannon, @ncoghlan: Are you ok to remove these hacks? It seems like https://bugs.python.org/issue15386 is already tested by test_import.test_there_can_be_only_one(). "import imp" was replaced with "import _imp" incommit be7e49f:
At least, I can say that importlib breaks quickly with the following change:
|
As long as there's another test then I'm fine with the change. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After reading through the issues and doing some testing on the latest version, I checked to see if the issue is still occurring:
I haven't worked out how yet, but importlib.machinery is managing to bypass the replacement of importlib._bootstrap with _frozen_importlib:
Since FileFinder
was moved from _bootstrap
to _bootstrap_external
I replaced the reference when I ran through the process in the interpreter:
Based upon the outputs, it looks like the issue was solved at some point by having importlib._bootstrap_external.FileFinder
and importlib.machinery.FileFinder
refer to the same class, _frozen_importlib_external.FileFinder
. To ensure this is happening, an assertion such as this could be used:
# ...
self.assertEqual(importlib.machinery.FileFinder,
importlib._bootstrap_external.FileFinder,
msg = "Both locations should refer to the same class.")
It might be a bit bandage solution still since it does not explain why the override was occurring in the first place, but at least it no longer happens with FileFinder
.
I merged your PR. If someone considers than test_there_can_be_only_one() is not enough, please add a new test. |
importlib initialisation changed quite a bit when the external import bootstrapping was split out to a separate step, so it's quite plausible that the previous odd behaviour was a result of FileFinder being defined in the core import system bootstrap module. |
bpo-15386, bpo-37473: test_import, regrtest and libregrtest no longer import importlib as soon as possible, as the first import, "to test bpo-15386". It is tested by test_import.test_there_can_be_only_one(). Sort test_import imports.
bpo-15386, bpo-37473: test_import, regrtest and libregrtest no longer import importlib as soon as possible, as the first import, "to test bpo-15386". It is tested by test_import.test_there_can_be_only_one(). Sort test_import imports.
bpo-15386, bpo-37473: test_import, regrtest and libregrtest no longer
import importlib as soon as possible, as the first import, "to test
bpo-15386".
Sort test_import imports.
https://bugs.python.org/issue37473