Skip to content

Commit

Permalink
Merge pull request #8419 from pytest-dev/all-repos_autofix_all-repos-…
Browse files Browse the repository at this point in the history
…manual

clean up mkdtemp usage
  • Loading branch information
asottile committed Mar 9, 2021
2 parents 79b03ce + 7a6ec56 commit 38d8deb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
12 changes: 5 additions & 7 deletions doc/en/fixture.rst
Expand Up @@ -2228,20 +2228,18 @@ file:
# content of conftest.py
import os
import shutil
import tempfile
import pytest
@pytest.fixture
def cleandir():
old_cwd = os.getcwd()
newpath = tempfile.mkdtemp()
os.chdir(newpath)
yield
os.chdir(old_cwd)
shutil.rmtree(newpath)
with tempfile.TemporaryDirectory() as newpath:
old_cwd = os.getcwd()
os.chdir(newpath)
yield
os.chdir(old_cwd)
and declare its use in a test module via a ``usefixtures`` marker:

Expand Down
6 changes: 2 additions & 4 deletions testing/test_assertrewrite.py
Expand Up @@ -1395,12 +1395,10 @@ def test_cwd_changed(self, pytester: Pytester, monkeypatch) -> None:
**{
"test_setup_nonexisting_cwd.py": """\
import os
import shutil
import tempfile
d = tempfile.mkdtemp()
os.chdir(d)
shutil.rmtree(d)
with tempfile.TemporaryDirectory() as d:
os.chdir(d)
""",
"test_test.py": """\
def test():
Expand Down

0 comments on commit 38d8deb

Please sign in to comment.