summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRan Benita <ran@unusedvar.com>2021-03-04 18:34:19 +0200
committerGitHub <noreply@github.com>2021-03-04 18:34:19 +0200
commit6e7dc8bac831cd8cf7a53b08efa366bd84f0c0fe (patch)
tree8501ad3839bb098676d9d3354979cef6e218d95c
parentc14a9adba35ac675ce3e825d34d01d5bb51748c3 (diff)
parent514f8e068080b374b470f6c9f349c48edfc0d3d8 (diff)
downloadpytest-6e7dc8bac831cd8cf7a53b08efa366bd84f0c0fe.tar.gz
Merge pull request #8357 from matthewhughes934/remove-tmpdir-from-tests
Remove tmpdir from tests
-rw-r--r--testing/code/test_source.py4
-rw-r--r--testing/python/collect.py2
-rw-r--r--testing/python/integration.py2
-rw-r--r--testing/test_collection.py51
-rw-r--r--testing/test_conftest.py14
5 files changed, 36 insertions, 37 deletions
diff --git a/testing/code/test_source.py b/testing/code/test_source.py
index 083a7911f..5f2c6b1ea 100644
--- a/testing/code/test_source.py
+++ b/testing/code/test_source.py
@@ -286,9 +286,7 @@ def test_deindent() -> None:
assert lines == ["def f():", " def g():", " pass"]
-def test_source_of_class_at_eof_without_newline(
- tmpdir, _sys_snapshot, tmp_path: Path
-) -> None:
+def test_source_of_class_at_eof_without_newline(_sys_snapshot, tmp_path: Path) -> None:
# this test fails because the implicit inspect.getsource(A) below
# does not return the "x = 1" last line.
source = Source(
diff --git a/testing/python/collect.py b/testing/python/collect.py
index c52fb017d..4256851e2 100644
--- a/testing/python/collect.py
+++ b/testing/python/collect.py
@@ -274,7 +274,7 @@ class TestFunction:
pytester.makepyfile(
"""
class A(object):
- def __call__(self, tmpdir):
+ def __call__(self, tmp_path):
0/0
test_a = A()
diff --git a/testing/python/integration.py b/testing/python/integration.py
index 8576fcee3..1ab2149ff 100644
--- a/testing/python/integration.py
+++ b/testing/python/integration.py
@@ -234,7 +234,7 @@ class TestMockDecoration:
@mock.patch("os.path.abspath")
@mock.patch("os.path.normpath")
@mock.patch("os.path.basename", new=mock_basename)
- def test_someting(normpath, abspath, tmpdir):
+ def test_someting(normpath, abspath, tmp_path):
abspath.return_value = "this"
os.path.normpath(os.path.abspath("hello"))
normpath.assert_any_call("this")
diff --git a/testing/test_collection.py b/testing/test_collection.py
index 298c2dde1..055d27476 100644
--- a/testing/test_collection.py
+++ b/testing/test_collection.py
@@ -127,16 +127,16 @@ class TestCollector:
class TestCollectFS:
def test_ignored_certain_directories(self, pytester: Pytester) -> None:
- tmpdir = pytester.path
- ensure_file(tmpdir / "build" / "test_notfound.py")
- ensure_file(tmpdir / "dist" / "test_notfound.py")
- ensure_file(tmpdir / "_darcs" / "test_notfound.py")
- ensure_file(tmpdir / "CVS" / "test_notfound.py")
- ensure_file(tmpdir / "{arch}" / "test_notfound.py")
- ensure_file(tmpdir / ".whatever" / "test_notfound.py")
- ensure_file(tmpdir / ".bzr" / "test_notfound.py")
- ensure_file(tmpdir / "normal" / "test_found.py")
- for x in Path(str(tmpdir)).rglob("test_*.py"):
+ tmp_path = pytester.path
+ ensure_file(tmp_path / "build" / "test_notfound.py")
+ ensure_file(tmp_path / "dist" / "test_notfound.py")
+ ensure_file(tmp_path / "_darcs" / "test_notfound.py")
+ ensure_file(tmp_path / "CVS" / "test_notfound.py")
+ ensure_file(tmp_path / "{arch}" / "test_notfound.py")
+ ensure_file(tmp_path / ".whatever" / "test_notfound.py")
+ ensure_file(tmp_path / ".bzr" / "test_notfound.py")
+ ensure_file(tmp_path / "normal" / "test_found.py")
+ for x in tmp_path.rglob("test_*.py"):
x.write_text("def test_hello(): pass", "utf-8")
result = pytester.runpytest("--collect-only")
@@ -226,10 +226,12 @@ class TestCollectFS:
norecursedirs = mydir xyz*
"""
)
- tmpdir = pytester.path
- ensure_file(tmpdir / "mydir" / "test_hello.py").write_text("def test_1(): pass")
- ensure_file(tmpdir / "xyz123" / "test_2.py").write_text("def test_2(): 0/0")
- ensure_file(tmpdir / "xy" / "test_ok.py").write_text("def test_3(): pass")
+ tmp_path = pytester.path
+ ensure_file(tmp_path / "mydir" / "test_hello.py").write_text(
+ "def test_1(): pass"
+ )
+ ensure_file(tmp_path / "xyz123" / "test_2.py").write_text("def test_2(): 0/0")
+ ensure_file(tmp_path / "xy" / "test_ok.py").write_text("def test_3(): pass")
rec = pytester.inline_run()
rec.assertoutcome(passed=1)
rec = pytester.inline_run("xyz123/test_2.py")
@@ -242,10 +244,10 @@ class TestCollectFS:
testpaths = gui uts
"""
)
- tmpdir = pytester.path
- ensure_file(tmpdir / "env" / "test_1.py").write_text("def test_env(): pass")
- ensure_file(tmpdir / "gui" / "test_2.py").write_text("def test_gui(): pass")
- ensure_file(tmpdir / "uts" / "test_3.py").write_text("def test_uts(): pass")
+ tmp_path = pytester.path
+ ensure_file(tmp_path / "env" / "test_1.py").write_text("def test_env(): pass")
+ ensure_file(tmp_path / "gui" / "test_2.py").write_text("def test_gui(): pass")
+ ensure_file(tmp_path / "uts" / "test_3.py").write_text("def test_uts(): pass")
# executing from rootdir only tests from `testpaths` directories
# are collected
@@ -255,7 +257,7 @@ class TestCollectFS:
# check that explicitly passing directories in the command-line
# collects the tests
for dirname in ("env", "gui", "uts"):
- items, reprec = pytester.inline_genitems(tmpdir.joinpath(dirname))
+ items, reprec = pytester.inline_genitems(tmp_path.joinpath(dirname))
assert [x.name for x in items] == ["test_%s" % dirname]
# changing cwd to each subdirectory and running pytest without
@@ -628,10 +630,9 @@ class TestSession:
class Test_getinitialnodes:
def test_global_file(self, pytester: Pytester) -> None:
- tmpdir = pytester.path
- x = ensure_file(tmpdir / "x.py")
- with tmpdir.cwd():
- config = pytester.parseconfigure(x)
+ tmp_path = pytester.path
+ x = ensure_file(tmp_path / "x.py")
+ config = pytester.parseconfigure(x)
col = pytester.getnode(config, x)
assert isinstance(col, pytest.Module)
assert col.name == "x.py"
@@ -645,8 +646,8 @@ class Test_getinitialnodes:
The parent chain should match: Module<x.py> -> Package<subdir> -> Session.
Session's parent should always be None.
"""
- tmpdir = pytester.path
- subdir = tmpdir.joinpath("subdir")
+ tmp_path = pytester.path
+ subdir = tmp_path.joinpath("subdir")
x = ensure_file(subdir / "x.py")
ensure_file(subdir / "__init__.py")
with subdir.cwd():
diff --git a/testing/test_conftest.py b/testing/test_conftest.py
index 80f2a6d0b..3497b7cc4 100644
--- a/testing/test_conftest.py
+++ b/testing/test_conftest.py
@@ -44,15 +44,15 @@ class TestConftestValueAccessGlobal:
def basedir(
self, request, tmp_path_factory: TempPathFactory
) -> Generator[Path, None, None]:
- tmpdir = tmp_path_factory.mktemp("basedir", numbered=True)
- tmpdir.joinpath("adir/b").mkdir(parents=True)
- tmpdir.joinpath("adir/conftest.py").write_text("a=1 ; Directory = 3")
- tmpdir.joinpath("adir/b/conftest.py").write_text("b=2 ; a = 1.5")
+ tmp_path = tmp_path_factory.mktemp("basedir", numbered=True)
+ tmp_path.joinpath("adir/b").mkdir(parents=True)
+ tmp_path.joinpath("adir/conftest.py").write_text("a=1 ; Directory = 3")
+ tmp_path.joinpath("adir/b/conftest.py").write_text("b=2 ; a = 1.5")
if request.param == "inpackage":
- tmpdir.joinpath("adir/__init__.py").touch()
- tmpdir.joinpath("adir/b/__init__.py").touch()
+ tmp_path.joinpath("adir/__init__.py").touch()
+ tmp_path.joinpath("adir/b/__init__.py").touch()
- yield tmpdir
+ yield tmp_path
def test_basic_init(self, basedir: Path) -> None:
conftest = PytestPluginManager()