Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4f85cec

Browse files
authored
gh-93353: regrtest supports checking tmp files with -j2 (#93909)
regrtest now also implements checking for leaked temporary files anddirectories when using -jN for N >= 2. Use tempfile.mkdtemp() tocreate the temporary directory. Skip this check on WASI.
1 parent138db8e commit4f85cec

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

‎Lib/test/libregrtest/runtest_mp.py‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
importsignal
77
importsubprocess
88
importsys
9+
importtempfile
910
importthreading
1011
importtime
1112
importtraceback
@@ -273,14 +274,16 @@ def _run_process(self, test_name: str, tmp_dir: str) -> tuple[int, str, str]:
273274
self.current_test_name=None
274275

275276
def_runtest(self,test_name:str)->MultiprocessResult:
276-
ifself.ns.use_mp==1:
277+
# Don't check for leaked temporary files and directories if Python is
278+
# run on WASI. WASI don't pass environment variables like TMPDIR to
279+
# worker processes.
280+
ifnotsupport.is_wasi:
277281
# gh-93353: Check for leaked temporary files in the parent process,
278282
# since the deletion of temporary files can happen late during
279283
# Python finalization: too late for libregrtest.
280-
tmp_dir=os.getcwd()+'_tmpdir'
284+
tmp_dir=tempfile.mkdtemp(prefix="test_python_")
281285
tmp_dir=os.path.abspath(tmp_dir)
282286
try:
283-
os.mkdir(tmp_dir)
284287
retcode,stdout=self._run_process(test_name,tmp_dir)
285288
finally:
286289
tmp_files=os.listdir(tmp_dir)

‎Lib/test/test_regrtest.py‎

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,6 +1357,8 @@ def test_cleanup(self):
13571357
fornameinnames:
13581358
self.assertFalse(os.path.exists(name),name)
13591359

1360+
@unittest.skipIf(support.is_wasi,
1361+
'checking temp files is not implemented on WASI')
13601362
deftest_leak_tmp_file(self):
13611363
code=textwrap.dedent(r"""
13621364
import os.path
@@ -1369,15 +1371,17 @@ def test_leak_tmp_file(self):
13691371
with open(filename, "wb") as fp:
13701372
fp.write(b'content')
13711373
""")
1372-
testname=self.create_test(code=code)
1374+
testnames=[self.create_test(code=code)for_inrange(3)]
13731375

1374-
output=self.run_tests("--fail-env-changed","-v","-j1",testname,exitcode=3)
1375-
self.check_executed_tests(output, [testname],
1376-
env_changed=[testname],
1377-
fail_env_changed=True)
1378-
self.assertIn(f"Warning --{testname} leaked temporary "
1379-
f"files (1): mytmpfile",
1380-
output)
1376+
output=self.run_tests("--fail-env-changed","-v","-j2",*testnames,exitcode=3)
1377+
self.check_executed_tests(output,testnames,
1378+
env_changed=testnames,
1379+
fail_env_changed=True,
1380+
randomize=True)
1381+
fortestnameintestnames:
1382+
self.assertIn(f"Warning --{testname} leaked temporary "
1383+
f"files (1): mytmpfile",
1384+
output)
13811385

13821386

13831387
classTestUtils(unittest.TestCase):
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
regrtest now checks if a test leaks temporary files or directories if run
2+
with -jN option. Patch by Victor Stinner.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp