Skip to content

Commit 6e7dc8b

Browse files
authored
Merge pull request #8357 from matthewhughes934/remove-tmpdir-from-tests
Remove tmpdir from tests
2 parents c14a9ad + 514f8e0 commit 6e7dc8b

File tree

5 files changed

+36
-37
lines changed

5 files changed

+36
-37
lines changed

testing/code/test_source.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,7 @@ def g():
286286
assert lines == ["def f():", " def g():", " pass"]
287287

288288

289-
def test_source_of_class_at_eof_without_newline(
290-
tmpdir, _sys_snapshot, tmp_path: Path
291-
) -> None:
289+
def test_source_of_class_at_eof_without_newline(_sys_snapshot, tmp_path: Path) -> None:
292290
# this test fails because the implicit inspect.getsource(A) below
293291
# does not return the "x = 1" last line.
294292
source = Source(

testing/python/collect.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ def test_function_as_object_instance_ignored(self, pytester: Pytester) -> None:
274274
pytester.makepyfile(
275275
"""
276276
class A(object):
277-
def __call__(self, tmpdir):
277+
def __call__(self, tmp_path):
278278
0/0
279279
280280
test_a = A()

testing/python/integration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ def mock_basename(path):
234234
@mock.patch("os.path.abspath")
235235
@mock.patch("os.path.normpath")
236236
@mock.patch("os.path.basename", new=mock_basename)
237-
def test_someting(normpath, abspath, tmpdir):
237+
def test_someting(normpath, abspath, tmp_path):
238238
abspath.return_value = "this"
239239
os.path.normpath(os.path.abspath("hello"))
240240
normpath.assert_any_call("this")

testing/test_collection.py

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -127,16 +127,16 @@ def test_foo():
127127

128128
class TestCollectFS:
129129
def test_ignored_certain_directories(self, pytester: Pytester) -> None:
130-
tmpdir = pytester.path
131-
ensure_file(tmpdir / "build" / "test_notfound.py")
132-
ensure_file(tmpdir / "dist" / "test_notfound.py")
133-
ensure_file(tmpdir / "_darcs" / "test_notfound.py")
134-
ensure_file(tmpdir / "CVS" / "test_notfound.py")
135-
ensure_file(tmpdir / "{arch}" / "test_notfound.py")
136-
ensure_file(tmpdir / ".whatever" / "test_notfound.py")
137-
ensure_file(tmpdir / ".bzr" / "test_notfound.py")
138-
ensure_file(tmpdir / "normal" / "test_found.py")
139-
for x in Path(str(tmpdir)).rglob("test_*.py"):
130+
tmp_path = pytester.path
131+
ensure_file(tmp_path / "build" / "test_notfound.py")
132+
ensure_file(tmp_path / "dist" / "test_notfound.py")
133+
ensure_file(tmp_path / "_darcs" / "test_notfound.py")
134+
ensure_file(tmp_path / "CVS" / "test_notfound.py")
135+
ensure_file(tmp_path / "{arch}" / "test_notfound.py")
136+
ensure_file(tmp_path / ".whatever" / "test_notfound.py")
137+
ensure_file(tmp_path / ".bzr" / "test_notfound.py")
138+
ensure_file(tmp_path / "normal" / "test_found.py")
139+
for x in tmp_path.rglob("test_*.py"):
140140
x.write_text("def test_hello(): pass", "utf-8")
141141

142142
result = pytester.runpytest("--collect-only")
@@ -226,10 +226,12 @@ def test_custom_norecursedirs(self, pytester: Pytester) -> None:
226226
norecursedirs = mydir xyz*
227227
"""
228228
)
229-
tmpdir = pytester.path
230-
ensure_file(tmpdir / "mydir" / "test_hello.py").write_text("def test_1(): pass")
231-
ensure_file(tmpdir / "xyz123" / "test_2.py").write_text("def test_2(): 0/0")
232-
ensure_file(tmpdir / "xy" / "test_ok.py").write_text("def test_3(): pass")
229+
tmp_path = pytester.path
230+
ensure_file(tmp_path / "mydir" / "test_hello.py").write_text(
231+
"def test_1(): pass"
232+
)
233+
ensure_file(tmp_path / "xyz123" / "test_2.py").write_text("def test_2(): 0/0")
234+
ensure_file(tmp_path / "xy" / "test_ok.py").write_text("def test_3(): pass")
233235
rec = pytester.inline_run()
234236
rec.assertoutcome(passed=1)
235237
rec = pytester.inline_run("xyz123/test_2.py")
@@ -242,10 +244,10 @@ def test_testpaths_ini(self, pytester: Pytester, monkeypatch: MonkeyPatch) -> No
242244
testpaths = gui uts
243245
"""
244246
)
245-
tmpdir = pytester.path
246-
ensure_file(tmpdir / "env" / "test_1.py").write_text("def test_env(): pass")
247-
ensure_file(tmpdir / "gui" / "test_2.py").write_text("def test_gui(): pass")
248-
ensure_file(tmpdir / "uts" / "test_3.py").write_text("def test_uts(): pass")
247+
tmp_path = pytester.path
248+
ensure_file(tmp_path / "env" / "test_1.py").write_text("def test_env(): pass")
249+
ensure_file(tmp_path / "gui" / "test_2.py").write_text("def test_gui(): pass")
250+
ensure_file(tmp_path / "uts" / "test_3.py").write_text("def test_uts(): pass")
249251

250252
# executing from rootdir only tests from `testpaths` directories
251253
# are collected
@@ -255,7 +257,7 @@ def test_testpaths_ini(self, pytester: Pytester, monkeypatch: MonkeyPatch) -> No
255257
# check that explicitly passing directories in the command-line
256258
# collects the tests
257259
for dirname in ("env", "gui", "uts"):
258-
items, reprec = pytester.inline_genitems(tmpdir.joinpath(dirname))
260+
items, reprec = pytester.inline_genitems(tmp_path.joinpath(dirname))
259261
assert [x.name for x in items] == ["test_%s" % dirname]
260262

261263
# changing cwd to each subdirectory and running pytest without
@@ -628,10 +630,9 @@ def test_method(self):
628630

629631
class Test_getinitialnodes:
630632
def test_global_file(self, pytester: Pytester) -> None:
631-
tmpdir = pytester.path
632-
x = ensure_file(tmpdir / "x.py")
633-
with tmpdir.cwd():
634-
config = pytester.parseconfigure(x)
633+
tmp_path = pytester.path
634+
x = ensure_file(tmp_path / "x.py")
635+
config = pytester.parseconfigure(x)
635636
col = pytester.getnode(config, x)
636637
assert isinstance(col, pytest.Module)
637638
assert col.name == "x.py"
@@ -645,8 +646,8 @@ def test_pkgfile(self, pytester: Pytester) -> None:
645646
The parent chain should match: Module<x.py> -> Package<subdir> -> Session.
646647
Session's parent should always be None.
647648
"""
648-
tmpdir = pytester.path
649-
subdir = tmpdir.joinpath("subdir")
649+
tmp_path = pytester.path
650+
subdir = tmp_path.joinpath("subdir")
650651
x = ensure_file(subdir / "x.py")
651652
ensure_file(subdir / "__init__.py")
652653
with subdir.cwd():

testing/test_conftest.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ class TestConftestValueAccessGlobal:
4444
def basedir(
4545
self, request, tmp_path_factory: TempPathFactory
4646
) -> Generator[Path, None, None]:
47-
tmpdir = tmp_path_factory.mktemp("basedir", numbered=True)
48-
tmpdir.joinpath("adir/b").mkdir(parents=True)
49-
tmpdir.joinpath("adir/conftest.py").write_text("a=1 ; Directory = 3")
50-
tmpdir.joinpath("adir/b/conftest.py").write_text("b=2 ; a = 1.5")
47+
tmp_path = tmp_path_factory.mktemp("basedir", numbered=True)
48+
tmp_path.joinpath("adir/b").mkdir(parents=True)
49+
tmp_path.joinpath("adir/conftest.py").write_text("a=1 ; Directory = 3")
50+
tmp_path.joinpath("adir/b/conftest.py").write_text("b=2 ; a = 1.5")
5151
if request.param == "inpackage":
52-
tmpdir.joinpath("adir/__init__.py").touch()
53-
tmpdir.joinpath("adir/b/__init__.py").touch()
52+
tmp_path.joinpath("adir/__init__.py").touch()
53+
tmp_path.joinpath("adir/b/__init__.py").touch()
5454

55-
yield tmpdir
55+
yield tmp_path
5656

5757
def test_basic_init(self, basedir: Path) -> None:
5858
conftest = PytestPluginManager()

0 commit comments

Comments
 (0)