Author vstinner
Recipients shihai1991, vstinner
Date 2020-09-04.15:36:12
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1599233772.93.0.299899979889.issue41718@roundup.psfhosted.org>
In-reply-to
Content
Follow-up of bpo-40275.

While investigating a crash on AIX (bpo-40068), I noticed that test_threading crashed because the test imports the logging module, and the logging has a bug on AIX on fork. I created an issue to reduce the number of imports made by "import test.support":

https://bugs.python.org/issue40275
I would prefer to better isolate tests: test_threading should only test the threading module, not the logging module.

Thanks to the hard work of Hai Shi, "import test.support" now imports only 37 modules instead of 171! He split the 3200 lines of Lib/test/support/__init__.py into new helper submodules: bytecode, import, threading, socket, etc. For example, TESTFN now comes from test.support.os_helper.
Sadly, test.regrtest.save_env still imports asyncio and multiprocessing, and so in practice, running any test using "python -m test (...)" still imports around 233 modules :-(

I measured the number of imports done in practice using the following file, Lib/test/test_sys_modules.py:
----
import unittest
from test import support
import sys

class Tests(unittest.TestCase):
    def test_bug(self):
        modules = sorted(sys.modules)
        print("sys.modules:")
        print("")
        import pprint
        pprint.pprint(modules)
        print("")
        print("len(sys.modules):", len(modules))

def test_main():
    support.run_unittest(Tests)

if __name__ == "__main__":
    test_main()
----

master:

* ./python -m test test_sys_modules: 233 modules (multiprocessing, asyncio, etc.)
* ./python Lib/test/test_sys_modules.py: 95 modules

3.9:

* ./python -m test test_sys_modules: 232
* ./python Lib/test/test_sys_modules.py: 117

3.5:

* ./python -m test test_sys_modules: 167
* ./python Lib/test/test_sys_modules.py: 151

2.7:

* ./python -m test test_sys_modules: 170
* ./python Lib/test/test_sys_modules.py: 122
History
Date User Action Args
2020-09-04 15:36:12vstinnersetrecipients: + vstinner, shihai1991
2020-09-04 15:36:12vstinnersetmessageid: <1599233772.93.0.299899979889.issue41718@roundup.psfhosted.org>
2020-09-04 15:36:12vstinnerlinkissue41718 messages
2020-09-04 15:36:12vstinnercreate