Skip to content

Commit 38d8deb

Browse files
authored
Merge pull request #8419 from pytest-dev/all-repos_autofix_all-repos-manual
clean up mkdtemp usage
2 parents 79b03ce + 7a6ec56 commit 38d8deb

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

doc/en/fixture.rst

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2228,20 +2228,18 @@ file:
22282228
# content of conftest.py
22292229
22302230
import os
2231-
import shutil
22322231
import tempfile
22332232
22342233
import pytest
22352234
22362235
22372236
@pytest.fixture
22382237
def cleandir():
2239-
old_cwd = os.getcwd()
2240-
newpath = tempfile.mkdtemp()
2241-
os.chdir(newpath)
2242-
yield
2243-
os.chdir(old_cwd)
2244-
shutil.rmtree(newpath)
2238+
with tempfile.TemporaryDirectory() as newpath:
2239+
old_cwd = os.getcwd()
2240+
os.chdir(newpath)
2241+
yield
2242+
os.chdir(old_cwd)
22452243
22462244
and declare its use in a test module via a ``usefixtures`` marker:
22472245

testing/test_assertrewrite.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,12 +1395,10 @@ def test_cwd_changed(self, pytester: Pytester, monkeypatch) -> None:
13951395
**{
13961396
"test_setup_nonexisting_cwd.py": """\
13971397
import os
1398-
import shutil
13991398
import tempfile
14001399
1401-
d = tempfile.mkdtemp()
1402-
os.chdir(d)
1403-
shutil.rmtree(d)
1400+
with tempfile.TemporaryDirectory() as d:
1401+
os.chdir(d)
14041402
""",
14051403
"test_test.py": """\
14061404
def test():

0 commit comments

Comments
 (0)