Skip to content

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

Description

@tomasr8

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

Activity

  1. MaximGit1 commented on Mar 16, 2025

    @MaximGit1
    Contributor

    Hello i would like to take for this

  2. sobolevn commented on Mar 16, 2025

    @sobolevn
    Member

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

  3. MaximGit1 commented on Mar 17, 2025

    @MaximGit1
    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?

  4. MaximGit1 commented on Mar 17, 2025

    @MaximGit1
    Contributor

    @sobolevn I finished

  5. vstinner commented on Mar 17, 2025

    @vstinner
    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()
  6. added a commit that references this issue on Apr 12, 2025
  7. Eclips4 commented on Apr 12, 2025

    @Eclips4
    Member

    Thank you @MaximGit1 for fixing this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

easytestsTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or error

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions