Skip to content

Multiple tests failing when invoked directly via ./python Lib/test/... #131290

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

Closed
tomasr8 opened this issue Mar 15, 2025 · 6 comments
Closed

Multiple tests failing when invoked directly via ./python Lib/test/... #131290

tomasr8 opened this issue Mar 15, 2025 · 6 comments
Assignees
Labels
easy tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error

Comments

@tomasr8
Copy link
Member

tomasr8 commented Mar 15, 2025

Besides test_pickle reported in #131031, there are a few more (test_regrtest, test_metaclass and test_pyclbr):

~ ./python Lib/test/test_regrtest.py
...
Ran 115 tests in 35.727s

FAILED (failures=1, skipped=2)
~ ./python Lib/test/test_metaclass.py
...
Ran 1 test in 0.018s

FAILED (failures=1)
~ ./python Lib/test/test_pyclbr.py
...
Ran 6 tests in 1.720s

FAILED (failures=1, errors=1)

Linked PRs

@tomasr8 tomasr8 added the tests Tests in the Lib/test dir label Mar 15, 2025
@sobolevn sobolevn added the easy label Mar 16, 2025
@MaximGit1
Copy link
Contributor

Hello i would like to take for this

@sobolevn
Copy link
Member

@MaximGit1 Thank you, please go ahead and ask any questions you have :)

@picnixz picnixz added the type-bug An unexpected behavior, bug, or error label Mar 16, 2025
@MaximGit1
Copy link
Contributor

Hello, I am currently running "Lib/test/test_metaclass.py".

Running it directly (./python Lib/test/test_metaclass.py) works in the global namespace (main), so module becomes 'main'. This creates a conflict since the module should be called "test.test_metaclass".

To fix this, I decided to do this.

if __name__ == "__main__":
    __name__ = "test.test_metaclass"  # predefined name
    unittest.main()

I think this is the best solution because I don't change the logic of the tests. How good do you think this solution is?

@MaximGit1
Copy link
Contributor

@sobolevn I finished

@vstinner
Copy link
Member

For regrtest, I would prefer this fix:

diff --git a/Lib/test/test_regrtest.py b/Lib/test/test_regrtest.py
index 510c8f69631..7e317d5ab94 100644
--- a/Lib/test/test_regrtest.py
+++ b/Lib/test/test_regrtest.py
@@ -2546,4 +2546,5 @@ def test_test_result_get_state(self):
 
 
 if __name__ == '__main__':
+    setup.setup_process()
     unittest.main()

picnixz added a commit that referenced this issue Apr 12, 2025
@Eclips4
Copy link
Member

Eclips4 commented Apr 12, 2025

Thank you @MaximGit1 for fixing this!

@Eclips4 Eclips4 closed this as completed Apr 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
easy tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

6 participants