@@ -415,6 +415,28 @@ def finalize(self):
415415 os .system ("leaks %d" % os .getpid ())
416416
417417 def main (self , tests = None , ** kwargs ):
418+ global TEMPDIR
419+
420+ if sysconfig .is_python_build ():
421+ try :
422+ os .mkdir (TEMPDIR )
423+ except FileExistsError :
424+ pass
425+
426+ # Define a writable temp dir that will be used as cwd while running
427+ # the tests. The name of the dir includes the pid to allow parallel
428+ # testing (see the -j option).
429+ test_cwd = 'test_python_{}' .format (os .getpid ())
430+ test_cwd = os .path .join (TEMPDIR , test_cwd )
431+
432+ # Run the tests in a context manager that temporarily changes the CWD to a
433+ # temporary and writable directory. If it's not possible to create or
434+ # change the CWD, the original CWD will be used. The original CWD is
435+ # available from support.SAVEDCWD.
436+ with support .temp_cwd (test_cwd , quiet = True ):
437+ self ._main (tests , kwargs )
438+
439+ def _main (self , tests , kwargs ):
418440 self .ns = self .parse_args (kwargs )
419441
420442 if self .ns .slaveargs is not None :
@@ -473,26 +495,5 @@ def printlist(x, width=70, indent=4):
473495
474496
475497def main (tests = None , ** kwargs ):
498+ """Run the Python suite."""
476499 Regrtest ().main (tests = tests , ** kwargs )
477-
478-
479- def main_in_temp_cwd ():
480- """Run main() in a temporary working directory."""
481- if sysconfig .is_python_build ():
482- try :
483- os .mkdir (TEMPDIR )
484- except FileExistsError :
485- pass
486-
487- # Define a writable temp dir that will be used as cwd while running
488- # the tests. The name of the dir includes the pid to allow parallel
489- # testing (see the -j option).
490- test_cwd = 'test_python_{}' .format (os .getpid ())
491- test_cwd = os .path .join (TEMPDIR , test_cwd )
492-
493- # Run the tests in a context manager that temporarily changes the CWD to a
494- # temporary and writable directory. If it's not possible to create or
495- # change the CWD, the original CWD will be used. The original CWD is
496- # available from support.SAVEDCWD.
497- with support .temp_cwd (test_cwd , quiet = True ):
498- main ()
0 commit comments