| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
It breaks import machinery if the test module has submodules used in other tests.
|
Presumably the reload (the reason for the unload) was intentional. Do we know why that was added? Do those reasons still apply? |
Sorry, something went wrong.
| module_name = abs_module_name(result.test_name, ns.testdir) | ||
|
|
||
| # Remove the module from sys.module to reload it if it was already imported | ||
| sys.modules.pop(module_name, None) |
There was a problem hiding this comment.
Hum. I think that the problem is that only a single module is unload from sys.modules.
If we want to save/restore modules, IMO the whole sys.modules dictionary must be saved/restored. Not a single entry.
Would it make sense to save/restore the whole sys.modules dict? Would it fix #108927 ?
Sorry, something went wrong.
|
Tests crash with this change, and it means that there is other huge issue hidden until now.
It is already done in run_test() in main.py, so I do not understand why it did not have effect and why removing the module was needed here. |
Sorry, something went wrong.
|
Unloading the test module is done for 23 years (commit 5796d26) and so far, so I'm surprised that today it became a problem. Maybe it's not the right place to fix the issue. commit 5796d26794eee634a4a06637d99d8d5c58da2bdb
Author: Guido van Rossum <guido@python.org>
Date: Fri Apr 21 21:35:06 2000 +0000
Patch by Vladimir Marangozov to unload additionally imported modules
after each test has been run. This avoids excessive memory growth
during the tests.
diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py
index 6364d7179c..924890ab76 100755
--- a/Lib/test/regrtest.py
+++ b/Lib/test/regrtest.py
@@ -105,6 +105,7 @@ def main(tests=None, testdir=None):
if single:
tests = tests[:1]
test_support.verbose = verbose # Tell tests to be moderately quiet
+ save_modules = sys.modules.keys()
for test in tests:
if not quiet:
print test
@@ -118,6 +119,10 @@ def main(tests=None, testdir=None):
print "test", test,
print "skipped -- an optional feature could not be imported"
skipped.append(test)
+ # Unload the newly imported modules (best effort finalization)
+ for module in sys.modules.keys():
+ if module not in save_modules:
+ test_support.unload(module)
if good and not quiet:
if not bad and not skipped and len(good) > 1:
print "All",
|
Sorry, something went wrong.
I would prefer to dig deeper before changing this code. |
Sorry, something went wrong.
|
The crash is not related to this change. See #108976. If exclude test_pdb, all tests are passed successfully. |
Sorry, something went wrong.
Ah, that code does not work since 3.0. It saves sys.modules.keys() which is a view in Python 3, and reflects the current content of sys.modules, so the code never finds any "newly imported" modules. |
Sorry, something went wrong.
|
|
||
| # Unload the newly imported modules (best effort finalization) | ||
| for module in sys.modules.keys(): | ||
| for module in list(sys.modules): |
There was a problem hiding this comment.
| for module in list(sys.modules): | |
| for module in sys.modules: |
Sorry, something went wrong.
There was a problem hiding this comment.
No it does not work, because the dict is modified during iteration.
Sorry, something went wrong.
…Wav.rst Co-authored-by: Brett Cannon <brett@python.org>
|
|
||
| # Unload the newly imported modules (best effort finalization) | ||
| for module in sys.modules.keys(): | ||
| for module in list(sys.modules): |
There was a problem hiding this comment.
I don't understand this code. Why do we have to unload test modules?
If it's important to unload test modules, I would suggest to move this code inside single.py, to make a more consistent behavior for the different ways to run tests.
Sorry, something went wrong.
There was a problem hiding this comment.
Do you ask why the code of libregrtest is so complicated? 🤷♂️
I think that it only makes sense in the single-process run. As well as removing the testing module before reloading in _load_run_test(). In the multi-process run it is only a waste of time. As well as significant part of save_env (except cleaning up external resources like filesystem).
Sorry, something went wrong.
Oh... I see :-) So if the code is dead for 20+ years, maybe remove it? I don't know what's the best option here. I would expect that running a test would restore Python (sys.modules) in the exact same state. |
Sorry, something went wrong.
There was a problem hiding this comment.
LGTM. Thanks for updated tests. I confirm that tests fail I revert Lib/test/libregrtest/ changes.
Sorry, something went wrong.
Co-authored-by: Victor Stinner <vstinner@python.org>
|
Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.11, 3.12. |
Sorry, something went wrong.
|
GH-112711 is a backport of this pull request to the 3.12 branch. |
Sorry, something went wrong.
…nGH-108952) It breaks import machinery if the test module has submodules used in other tests. (cherry picked from commit e08b70f) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
|
GH-112712 is a backport of this pull request to the 3.11 branch. |
Sorry, something went wrong.
…nGH-108952) It breaks import machinery if the test module has submodules used in other tests. (cherry picked from commit e08b70f) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
|
It looks like the new test fails when running the tests from an installed Python installation (see https://buildbot.python.org/all/#/builders/350/builds/4974 and https://buildbot.python.org/all/#/builders/1154/builds/418), could someone take a look? |
Sorry, something went wrong.
Sorry, something went wrong.
FTR we are seeing the failures with the recently released 3.11.7. |
Sorry, something went wrong.
I suppose that #112784 already fixed the issue in the 3.11 branch. Sadly, this fix is not part of 3.11.7 release. Buildbots were too slow to report the failure on the 3.11 branch before the release? It seems like we have "Installed" buildbot builders on the 3.11 branch. |
Sorry, something went wrong.
|
Yes. What's done is done, but may I suggest a release not be made with commits before the buildbots have time to recognize a failure? |
Sorry, something went wrong.
Ah right, there were less than 1 hour between the commit and the tag.
Usually, the branch is not locked around bugfix 3.x.y releases. cc @pablogsal 3.11 release manager. |
Sorry, something went wrong.
|
The release script blocks if there are failing build bots so this was releaseable because all buildbots were green at the time (or the API reported green). Is very difficult to time this correctly because even if we block a branch we do this hours before the release so we don't know when all builsbots have finished. We can discuss blocking a day in advance to prevent this from happening or some other mechanism. I will discuss this with other RMs to see what can be done. |
Sorry, something went wrong.
|
In my experience, it's rare to discover bugs so soon just after a release. I'm not sure that it's worth it to deeply change the release process. Maybe the release process should run tests on installed Python, rather than in the source code directory. |
Sorry, something went wrong.
…nGH-108952) It breaks import machinery if the test module has submodules used in other tests.
…nGH-108952) It breaks import machinery if the test module has submodules used in other tests.
| Back | FazBrowse Home | New Git URL |
The code that does this properly never worked since Python 3.0.
And removing only the tested module breaks import machinery if it has submodules used in other tests.