Skip to content

libregrtest: Reduce number of imports at startup #111881

Closed
@vstinner

Description

@vstinner

Currently, when a test is run by ./python -m test (...), the test starts with 170 modules already imported. The problem is that imports can have side effects and I would prefer to start tests in a "minimal environment".

Running a test with ./python -m test (...) only imports 164 modules.

Example by adding Lib/test/test_x.py:

import sys
print(len(sys.modules))

Output:

vstinner@mona$ ./python -m test test_x
170

vstinner@mona$ ./python -m test -j1 test_x
164

I propose to try to make more imports lazy: only import the module the first time that it's needed, tests are rarely "performance sensitive". It may improve the "startup time".

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    testsTests in the Lib/test dir

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions