Skip to content

Commit 20c59e3

Browse files
author
sousajf1
authored
#8204 migrate some tests to tmp_path fixture (#8209)
migrating some tests from tmpdir to tmp_path fixture
1 parent 5f11a35 commit 20c59e3

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

testing/code/test_excinfo.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -364,12 +364,12 @@ def test_excinfo_no_sourcecode():
364364
assert s == " File '<string>':1 in <module>\n ???\n"
365365

366366

367-
def test_excinfo_no_python_sourcecode(tmpdir):
367+
def test_excinfo_no_python_sourcecode(tmp_path: Path) -> None:
368368
# XXX: simplified locally testable version
369-
tmpdir.join("test.txt").write("{{ h()}}:")
369+
tmp_path.joinpath("test.txt").write_text("{{ h()}}:")
370370

371371
jinja2 = pytest.importorskip("jinja2")
372-
loader = jinja2.FileSystemLoader(str(tmpdir))
372+
loader = jinja2.FileSystemLoader(str(tmp_path))
373373
env = jinja2.Environment(loader=loader)
374374
template = env.get_template("test.txt")
375375
excinfo = pytest.raises(ValueError, template.render, h=h)

testing/test_argcomplete.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import subprocess
22
import sys
3+
from pathlib import Path
34

45
import pytest
6+
from _pytest.monkeypatch import MonkeyPatch
57

68
# Test for _argcomplete but not specific for any application.
79

@@ -65,19 +67,22 @@ def __call__(self, prefix, **kwargs):
6567

6668
class TestArgComplete:
6769
@pytest.mark.skipif("sys.platform in ('win32', 'darwin')")
68-
def test_compare_with_compgen(self, tmpdir):
70+
def test_compare_with_compgen(
71+
self, tmp_path: Path, monkeypatch: MonkeyPatch
72+
) -> None:
6973
from _pytest._argcomplete import FastFilesCompleter
7074

7175
ffc = FastFilesCompleter()
7276
fc = FilesCompleter()
7377

74-
with tmpdir.as_cwd():
75-
assert equal_with_bash("", ffc, fc, out=sys.stdout)
78+
monkeypatch.chdir(tmp_path)
7679

77-
tmpdir.ensure("data")
80+
assert equal_with_bash("", ffc, fc, out=sys.stdout)
7881

79-
for x in ["d", "data", "doesnotexist", ""]:
80-
assert equal_with_bash(x, ffc, fc, out=sys.stdout)
82+
tmp_path.cwd().joinpath("data").touch()
83+
84+
for x in ["d", "data", "doesnotexist", ""]:
85+
assert equal_with_bash(x, ffc, fc, out=sys.stdout)
8186

8287
@pytest.mark.skipif("sys.platform in ('win32', 'darwin')")
8388
def test_remove_dir_prefix(self):

0 commit comments

Comments
 (0)