summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_regrtest.py
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2022-06-14 11:43:02 (GMT)
committerGitHub <noreply@github.com>2022-06-14 11:43:02 (GMT)
commite566ce5496f1bad81c431aaee65e36d5e44771c5 (patch)
tree1c3ffbfc5d9ca5f3d82bb6b07b7b7d408e52fe05 /Lib/test/test_regrtest.py
parentb083450f8896bb4a29ac522e4474d91c056b9f32 (diff)
downloadcpython-e566ce5496f1bad81c431aaee65e36d5e44771c5.zip
cpython-e566ce5496f1bad81c431aaee65e36d5e44771c5.tar.gz
cpython-e566ce5496f1bad81c431aaee65e36d5e44771c5.tar.bz2
gh-93353: regrtest checks for leaked temporary files (#93776)
When running tests with -jN, create a temporary directory per process and mark a test as "environment changed" if a test leaks a temporary file or directory.
Diffstat (limited to 'Lib/test/test_regrtest.py')
-rw-r--r--Lib/test/test_regrtest.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/test/test_regrtest.py b/Lib/test/test_regrtest.py
index 133abf5..5c072ea 100644
--- a/Lib/test/test_regrtest.py
+++ b/Lib/test/test_regrtest.py
@@ -1357,6 +1357,26 @@ class ArgsTestCase(BaseTestCase):
for name in names:
self.assertFalse(os.path.exists(name), name)
+ def test_leak_tmp_file(self):
+ code = textwrap.dedent(r"""
+ import os.path
+ import tempfile
+ import unittest
+
+ class FileTests(unittest.TestCase):
+ def test_leak_tmp_file(self):
+ filename = os.path.join(tempfile.gettempdir(), 'mytmpfile')
+ with open(filename, "wb") as fp:
+ fp.write(b'content')
+ """)
+ testname = self.create_test(code=code)
+
+ output = self.run_tests("--fail-env-changed", "-v", "-j1", testname, exitcode=3)
+ self.check_executed_tests(output, [testname],
+ env_changed=[testname],
+ fail_env_changed=True)
+ self.assertIn("Warning -- Test leaked temporary files (1): mytmpfile", output)
+
class TestUtils(unittest.TestCase):
def test_format_duration(self):