Repository navigation
gh-108927: Fix removing testing modules from sys.modules #108952
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
Changes from 1 commit
339f260
e52be9b
68c014e
c1ad70c
3f25ab4
7673248
5df4c8b
eb7766b
0eae535
66437b5
8470b33
544c068
1e7ea34
56621ab
ba5597a
d025e22
1aae341
017f01d
5086405
b3ea8fa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -309,6 +309,8 @@ def run_tests_sequentially(self, runtests) -> None: | |
| else: | ||
| tracer = None | ||
|
|
||
| save_modules = set(sys.modules) | ||
|
|
||
| jobs = runtests.get_jobs() | ||
| if jobs is not None: | ||
| tests = count(jobs, 'test') | ||
|
|
@@ -331,6 +333,19 @@ def run_tests_sequentially(self, runtests) -> None: | |
|
|
||
| result = self.run_test(test_name, runtests, tracer) | ||
|
|
||
| # Unload the newly imported modules (best effort finalization) | ||
|
serhiy-storchaka marked this conversation as resolved.
|
||
| new_modules = [module for module in sys.modules | ||
| if module not in save_modules and | ||
| module.startswith("test.")] | ||
| for module in new_modules: | ||
| sys.modules.pop(module, None) | ||
| # Remove the attribute of the parent module. | ||
| parent, _, name = module.rpartition('.') | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe raise an error if the parent itself has a parent other than
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you mean? The parent should be "test" or start with "test.", because the module starts with "test.". If the parent starts with "test." it will be removed as well. If it was already removed before children, the code ignores KeyError.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If a test imports
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, if they were not imported before running tests. |
||
| try: | ||
| delattr(sys.modules[parent], name) | ||
| except (KeyError, AttributeError): | ||
| pass | ||
|
|
||
| if result.must_stop(self.fail_fast, self.fail_env_changed): | ||
| break | ||
|
|
||
|
|
||
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.
I would prefer to move this logic inside
libregrtest/single.py, in therun_single_test()function.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.
I did it, but it is only needed in single-process run. In multi-process run it only adds an overhead. So I moved it back.