diff --git a/testing/code/test_excinfo.py b/testing/code/test_excinfo.py index 19c888403..e6a9cbaf7 100644 --- a/testing/code/test_excinfo.py +++ b/testing/code/test_excinfo.py @@ -364,12 +364,12 @@ def test_excinfo_no_sourcecode(): assert s == " File '':1 in \n ???\n" -def test_excinfo_no_python_sourcecode(tmpdir): +def test_excinfo_no_python_sourcecode(tmp_path: Path) -> None: # XXX: simplified locally testable version - tmpdir.join("test.txt").write("{{ h()}}:") + tmp_path.joinpath("test.txt").write_text("{{ h()}}:") jinja2 = pytest.importorskip("jinja2") - loader = jinja2.FileSystemLoader(str(tmpdir)) + loader = jinja2.FileSystemLoader(str(tmp_path)) env = jinja2.Environment(loader=loader) template = env.get_template("test.txt") excinfo = pytest.raises(ValueError, template.render, h=h) diff --git a/testing/test_argcomplete.py b/testing/test_argcomplete.py index a3224be51..8c10e230b 100644 --- a/testing/test_argcomplete.py +++ b/testing/test_argcomplete.py @@ -1,7 +1,9 @@ import subprocess import sys +from pathlib import Path import pytest +from _pytest.monkeypatch import MonkeyPatch # Test for _argcomplete but not specific for any application. @@ -65,19 +67,22 @@ class FilesCompleter: class TestArgComplete: @pytest.mark.skipif("sys.platform in ('win32', 'darwin')") - def test_compare_with_compgen(self, tmpdir): + def test_compare_with_compgen( + self, tmp_path: Path, monkeypatch: MonkeyPatch + ) -> None: from _pytest._argcomplete import FastFilesCompleter ffc = FastFilesCompleter() fc = FilesCompleter() - with tmpdir.as_cwd(): - assert equal_with_bash("", ffc, fc, out=sys.stdout) + monkeypatch.chdir(tmp_path) - tmpdir.ensure("data") + assert equal_with_bash("", ffc, fc, out=sys.stdout) - for x in ["d", "data", "doesnotexist", ""]: - assert equal_with_bash(x, ffc, fc, out=sys.stdout) + tmp_path.cwd().joinpath("data").touch() + + for x in ["d", "data", "doesnotexist", ""]: + assert equal_with_bash(x, ffc, fc, out=sys.stdout) @pytest.mark.skipif("sys.platform in ('win32', 'darwin')") def test_remove_dir_prefix(self):