11from buildbot .process import factory
22from buildbot .steps .shell import Configure , Compile , ShellCommand
33
4- from .steps import Test , Clean , Install , LockInstall , Uninstall
4+ from .steps import Test , Clean , CleanupTest , Install , LockInstall , Uninstall
55
66master_branch_version = "3.9"
7+ CUSTOM_BRANCH_NAME = "custom"
78
89# This (default) timeout is for each individual test file.
910# It is a bit more than the default faulthandler timeout in regrtest.py
1011# (the latter isn't easily changed under Windows).
1112TEST_TIMEOUT = 20 * 60
1213
1314
15+ def regrtest_has_cleanup (branch ):
16+ # "python -m test --cleanup" is available in Python 3.7 and newer,
17+ # and in Python 2.7.
18+ return (branch not in ("3.4" , "3.5" , "3.6" , CUSTOM_BRANCH_NAME ))
19+
20+
1421class TaggedBuildFactory (factory .BuildFactory ):
1522 factory_tags = []
1623
@@ -58,7 +65,7 @@ class UnixBuild(TaggedBuildFactory):
5865 makeTarget = "all"
5966 test_timeout = None
6067
61- def setup (self , parallel , test_with_PTY = False , ** kwargs ):
68+ def setup (self , parallel , branch , test_with_PTY = False , ** kwargs ):
6269 self .addStep (
6370 Configure (
6471 command = ["./configure" , "--prefix" , "$(PWD)/target" ]
@@ -76,6 +83,13 @@ def setup(self, parallel, test_with_PTY=False, **kwargs):
7683 testopts = testopts + " " + parallel
7784 if "-j" not in testopts :
7885 testopts = "-j2 " + testopts
86+ cleantest = [
87+ "make" ,
88+ "cleantest" ,
89+ "TESTOPTS=" + testopts + " ${BUILDBOT_TESTOPTS}" ,
90+ "TESTPYTHONOPTS=" + self .interpreterFlags ,
91+ "TESTTIMEOUT=" + str (faulthandler_timeout ),
92+ ]
7993 test = [
8094 "make" ,
8195 "buildbottest" ,
@@ -93,6 +107,8 @@ def setup(self, parallel, test_with_PTY=False, **kwargs):
93107 warnOnFailure = True ,
94108 )
95109 )
110+ if regrtest_has_cleanup (branch ):
111+ self .addStep (CleanupTest (command = cleantest ))
96112 self .addStep (
97113 Test (command = test , timeout = self .test_timeout , usePTY = test_with_PTY )
98114 )
@@ -316,6 +332,9 @@ def setup(self, parallel, branch, **kwargs):
316332 timeout = TEST_TIMEOUT
317333 if branch != "2.7" :
318334 test_command += ["--timeout" , timeout - (5 * 60 )]
335+ if regrtest_has_cleanup (branch ):
336+ cleantest = test_command + ["--cleanup" ]
337+ self .addStep (CleanupTest (command = cleantest ))
319338 self .addStep (Test (command = test_command , timeout = timeout ))
320339 self .addStep (Clean (command = clean_command ))
321340
0 commit comments