Skip to content

clean up mkdtemp usage #8419

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions doc/en/fixture.rst
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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