Repository navigation
test.support has way too many imports #84456
Copy link
Copy link
Closed
Labels
Description
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee = None
closed_at = <Date 2020-09-04.15:37:27.746>
created_at = <Date 2020-04-13.22:24:51.262>
labels = ['tests', '3.10']
title = 'test.support has way too many imports'
updated_at = <Date 2020-09-04.15:37:27.744>
user = 'https://github.com/vstinner'bugs.python.org fields:
activity = <Date 2020-09-04.15:37:27.744>
actor = 'vstinner'
assignee = 'none'
closed = True
closed_date = <Date 2020-09-04.15:37:27.746>
closer = 'vstinner'
components = ['Tests']
creation = <Date 2020-04-13.22:24:51.262>
creator = 'vstinner'
dependencies = []
files = ['49197']
hgrepos = []
issue_num = 40275
keywords = ['patch']
message_count = 80.0
messages = ['366337', '366765', '366766', '366767', '366768', '366776', '366780', '366786', '366787', '366789', '366810', '366815', '366823', '367261', '367262', '367265', '367603', '367629', '367818', '368073', '368814', '368816', '368840', '369029', '369030', '369032', '369062', '369214', '369296', '370142', '370146', '370150', '370152', '370154', '370217', '370221', '371188', '371253', '371295', '371296', '371297', '371298', '371299', '371303', '371751', '372339', '372361', '372381', '372690', '372691', '373081', '373082', '373109', '373403', '374738', '374739', '374740', '374828', '374829', '374931', '375002', '375021', '375039', '375042', '375043', '375051', '375059', '375060', '375067', '375068', '375069', '375122', '375124', '375150', '375151', '375269', '375315', '375367', '375368', '376375']
nosy_count = 5.0
nosy_names = ['terry.reedy', 'vstinner', 'pablogsal', 'miss-islington', 'shihai1991']
pr_nums = ['19592', '19599', '19600', '19601', '19603', '19711', '19716', '19761', '19825', '19905', '20128', '20131', '20207', '20263', '20459', '20468', '20471', '20479', '20482', '20488', '20625', '20689', '20732', '20765', '20794', '20797', '20810', '20812', '20824', '20849', '20957', '21151', '21167', '21169', '21219', '21314', '21315', '21317', '21412', '21448', '21449', '21450', '21451', '21452', '21727', '21743', '21764', '21772', '21771', '21785', '21811']
priority = 'normal'
resolution = 'fixed'
stage = 'resolved'
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue40275'
versions = ['Python 3.10']Reactions are currently unavailable
Activity
vstinner commentedon Apr 13, 2020
test_threading.ThreadJoinOnShutdown.test_reinit_tls_after_fork() does crash on AIX: bpo-40068. One of the issue is that logging does crash at fork: bpo-40091. The strange thing is that test_threading doesn't use logging. I'm quite sure that logging is imported through test.support.
"import test.support" imports not less than 171... That's quite "heavy". It includes "heavy" modules like concurrent.futures, asyncio or multiprocessing.
It's maybe time to slice again test.support until submodules to reduce the number of imports to the bare minimum. For example, "import test.support" imports asyncio, whereas it's only used by very few tests. Maybe we should add "test.support.asyncioutils".
shihai1991 commentedon Apr 19, 2020
If we split some "heavy" modules to xxxutils, what benefits will we make in fact(more exact module importing behavior)?
serhiy-storchaka commentedon Apr 19, 2020
+1 for splitting test.support on several submodules!
Some imports can also be lazy.
serhiy-storchaka commentedon Apr 19, 2020
asyncio is now imported in unittest. Removing direct import from test.support does not help.
shihai1991 commentedon Apr 19, 2020
Oh, thanks, you are right. Looks like we need check which submodules should be splitted.
serhiy-storchaka commentedon Apr 19, 2020
logging is also imported in unittest and indirectly in asyncio.
serhiy-storchaka commentedon Apr 19, 2020
These three PRs combined reduce the number of imported modules from 179 to 105 (not including 24 modules imported by the bare interpreter) and reduce the hot import time from 160 ms to 80 ms.
shihai1991 commentedon Apr 19, 2020
Good job, serhiy. I tested your patches in my vm, the number of importing module have been reduced. Could you paste your performance benchmark test? I got a no siginificant change :( when I run:
$ ./python -m pyperf timeit --compare-to python3.9 "from test import support" -p 100
python3.9: ..................................................................................................... 820 ns +- 206 ns
python: ..................................................................................................... 809 ns +- 201 ns
Mean +- std dev: [python3.9] 820 ns +- 206 ns -> [python] 809 ns +- 201 ns: 1.01x faster (-1%)
Not significant!
serhiy-storchaka commentedon Apr 19, 2020
I used -X importtime.
Your benchmark measures the performance of look up in sys.modules.
shihai1991 commentedon Apr 19, 2020
In master branch:
import time: 5011 | 133562 | test.support
After apply serhiy's patches:
import time: 4863 | 66940 | test.support
vsajip commentedon Apr 20, 2020
What is the practical impact on the time taken for test runs? How much does the total time for a test run reduce as a result of refactoring test.support to minimise imports?
61 remaining items
vstinner commentedon Aug 10, 2020
test__osx_support and test_selectors are broken, examples:
https://github.com/python/cpython/pull/21806/checks?check_run_id=966438645
2020-08-10T12:04:20.7613070Z ======================================================================
2020-08-10T12:04:20.7613710Z ERROR: test__remove_unsupported_archs (test.test__osx_support.Test_OSXSupport)
2020-08-10T12:04:20.7616560Z ----------------------------------------------------------------------
and
2020-08-10T12:01:40.0736200Z ======================================================================
2020-08-10T12:01:40.0738440Z ERROR: test_register_bad_fd (test.test_selectors.KqueueSelectorTestCase)
2020-08-10T12:01:40.0742700Z ----------------------------------------------------------------------
Hai Shi: Would you mind to investigate this issue?
shihai1991 commentedon Aug 10, 2020
vstinner commentedon Aug 10, 2020
New changeset 490c542 by Hai Shi in branch 'master':
bpo-40275: Fix failed test cases by using test helpers (GH-21811)
490c542
vstinner commentedon Aug 10, 2020
Update.
"import test.support" now imports 37 modules, instead of 171 previously. It's way better!
Shorter list if imports made by unittest are ignored:
shihai1991 commentedon Aug 12, 2020
Hi, victor:
About https://bugs.python.org/issue40275#msg369214, shall we continue to improve the libregretest?
I am not sure about it.
vstinner commentedon Aug 13, 2020
If someone wants to continue the effort in libregrtest, I suggest to open a new issue. This one already has a long list of commits and messages about test.support.
See test.libregrtest.runtest_mp module for the "multiprocessing" implementation which uses subprocess. It's used when you run tests using -jN option. Almost all buildbots use -jN: see make buildbottest.
shihai1991 commentedon Aug 14, 2020
If someone wants to continue the effort in libregrtest, I suggest to open a new issue.
+1. And if there have any other test cases blocked by test.support, I suggest this bpo.
shihai1991 commentedon Aug 14, 2020
oh, sorry, missing a word: I suggest this bpo.->I suggest close this bpo.
vstinner commentedon Sep 4, 2020
Sadly, the work done on this issue is useless until test.regrtest imports less modules as well.
So I created bpo-41718 follow-up issue: "test.regrtest has way too many imports".
I consider that the work is done on test.support, so I close this issue.