Sitelet https://github.com/python/cpython/issues/93839
Skip to content

Move all stdlib tests in the test package #93839

Description

@vstinner

Currently, Python tests are scattered in multiple directories:

  • Lib/test/ (main one)
  • Lib/ctypes/test/
  • Lib/distutils/tests/
  • Lib/idlelib/idle_test/
  • Lib/lib2to3/tests/
  • Lib/tkinter/test/
  • Lib/unittest/test/

idlelib, ctypes, lib2to3, tkinter, unittest and distutils have their tests under their own packages. It causes multiple issues:

  • As a maintainer of Python, I have to look into these directories manually when refactoring "Python tests" (I cannot just look into Lib/test/).
  • Linux distributions have to manually put these directories into a separated packages if they want to make the main "python" package smaller, to put python tests into a separated package.
  • Makefile is more complicated since tests are installed separately, and so these directories should be listed explicitly in the TESTSUBDIRS variable.
  • Tools/scripts/generate_stdlib_module_names.py excludes manually these modules, since sys.stdlib_module_names excludes test modules.

I propose to move ctypes, idlelib, tkinter and unittest tests under Lib/test/.

For distutils and lib2to3, maybe we can just leave them where they are, since both modules are deprecated. distutils should be removed in Python 3.12. lib2to3 is scheduled for removal in Python 3.13.

Do you think that it's worth it to move these directories?

Activity

  1. vstinner commented on Jun 15, 2022

    @vstinner
    MemberAuthor

    It seems like the Windows installer only treat Lib/test/ separately: see Tools/msi/test/test.wixproj. I would be nice to also exclude the other test directories to make Python installation smaller on Windows.

    $ du -sh ctypes/test/ distutils/tests/ idlelib/idle_test/ lib2to3/tests/ tkinter/test/ unittest/test/
    348K	ctypes/test/
    336K	distutils/tests/
    624K	idlelib/idle_test/
    440K	lib2to3/tests/
    284K	tkinter/test/
    700K	unittest/test/
    

    The total is about 2 732 KB.

    On Fedora 36, the Python 3.10 tests (python3-test package) take around 54 MB in total (it includes idle_test, ctypes tests, etc.).

    $ sudo dnf install python3-test
    (...)
    Total download size: 9.7 M
    Installed size: 54 M
    
  2. rhettinger commented on Jun 15, 2022

    @rhettinger
    Contributor

    Do you think that it's worth it to move these directories?

    Yes, yes, yes!

  3. zware commented on Jun 15, 2022

    @zware
    Member

    This appears to duplicate #54781.

    I'm still in favor :)

  4. terryjreedy commented on Jun 21, 2022

    @terryjreedy
    Member

    Please leave idlelib/idle_test alone. Following gives some of reasons:
    #54781 (comment)
    There are also several references to files in this directory in idlelib and idlelib.test_idle files.

  5. merwok commented on Jun 21, 2022

    @merwok
    Member

    Could you exclude idle and distutils from your list, and attach the new PRs to the other ticket?

  6. added 2 commits that reference this issue on Jun 21, 2022
  7. vstinner commented on Jun 21, 2022

    @vstinner
    MemberAuthor

    I merged my ctypes and unittest PRs. Ok, let's continue in issue #54781.

  8. tiran commented on Jun 21, 2022

    @tiran
    Member

    PR #94043 broke testing on all WebAssembly platforms.

  9. reopened this on Jun 21, 2022
  10. vstinner commented on Jun 21, 2022

    @vstinner
    MemberAuthor

    PR #94043 broke testing on all WebAssembly platforms.

    Please comment #54781. This issue is a duplicate.

  11. tiran commented on Jun 21, 2022

    @tiran
    Member

    Commit #94043 used this ticket as reference.

  12. tiran commented on Jun 21, 2022

    @tiran
    Member

    There are actually two problems:

    # wasmtime run --mapdir .::../../ -- python.wasm -m test -v test_unittest
    == CPython 3.12.0a0 (heads/main-dirty:c735d545343, Jun 21 2022, 09:30:50) [Clang 14.0.4 (https://github.com/llvm/llvm-project 29f1039a7285a5c3a9c353d05414
    == wasi-0.0.0-wasm32-32bit little-endian
    == cwd: /python-wasm/cpython/builddir/wasi/build/test_python_859108æ
    == CPU count: 1
    == encodings: locale=UTF-8, FS=utf-8
    0:00:00 Run tests sequentially
    0:00:00 [1/1] test_unittest
    Failed to call load_tests:
    Traceback (most recent call last):
      File "/Lib/unittest/loader.py", line 130, in loadTestsFromModule
        return load_tests(self, tests, pattern)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/Lib/test/test_unittest/testmock/__init__.py", line 14, in load_tests
        __import__(modname)
        ^^^^^^^^^^^^^^^^^^^
      File "/Lib/test/test_unittest/testmock/testasync.py", line 9, in <module>
        support.requires_working_socket(module=True)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/Lib/test/support/__init__.py", line 543, in requires_working_socket
        raise unittest.SkipTest(msg)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    unittest.case.SkipTest: requires socket support
    
    test test_unittest crashed -- Traceback (most recent call last):
      File "/Lib/test/libregrtest/runtest.py", line 360, in _runtest_inner
        refleak = _runtest_inner2(ns, test_name)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/Lib/test/libregrtest/runtest.py", line 317, in _runtest_inner2
        test_runner()
        ^^^^^^^^^^^^^
      File "/Lib/test/libregrtest/runtest.py", line 280, in _test_module
        raise Exception("errors while loading tests")
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    Exception: errors while loading tests
    
    test_unittest failed (uncaught exception)
    
    == Tests result: FAILURE ==
    
    1 test failed:
        test_unittest
    
    Total duration: 132 ms
    Tests result: FAILURE
    
  13. added a commit that references this issue on Jun 21, 2022
  14. added a commit that references this issue on Jun 21, 2022
  15. arhadthedev commented on Jun 29, 2022

    @arhadthedev
    Member

    What's about Modules/_decimal/tests? Is it eligible for moving?

    • bench.py - move to pyperformance
    • formathelper.py, randdec.py, randfloat.py - convert these generators to unittest subtests
    • README.txt, runall-memorydebugger.sh, runall.bat - port to unittest and merge there
    • bignum.py, deccheck.py, formathelper.py, randdec.py, randfloat.py
  16. vstinner commented on Jun 29, 2022

    @vstinner
    MemberAuthor

    What's about Modules/_decimal/tests? Is it eligible for moving?

    It's not installed by make install, so I care less about this one :-)

  17. erlend-aasland commented on Jul 20, 2022

    @erlend-aasland
    Contributor

    Are the issues mentioned by Christian resolved? Can we close this?

  18. tiran commented on Jul 20, 2022

    @tiran
    Member

    Yes, they are.

  19. added a commit that references this issue on Dec 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions