From 0e5e4e03e64c9a607bcaf40f8192ca3049f8db53 Mon Sep 17 00:00:00 2001 From: Matthew Hughes Date: Sat, 20 Feb 2021 18:01:42 +0000 Subject: [PATCH 1/4] Remove some unused 'tmpdir's --- testing/code/test_source.py | 4 +--- testing/python/collect.py | 2 +- testing/python/integration.py | 2 +- 3 files changed, 3 insertions(+), 5 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..22ac6464b 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): 0/0 test_a = A() diff --git a/testing/python/integration.py b/testing/python/integration.py index 8576fcee3..77ebfa23e 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): abspath.return_value = "this" os.path.normpath(os.path.abspath("hello")) normpath.assert_any_call("this") From 09d4c5e30a54ea1a914d75d19e0762c53a264566 Mon Sep 17 00:00:00 2001 From: Matthew Hughes Date: Sat, 20 Feb 2021 18:05:43 +0000 Subject: [PATCH 2/4] Rename variables 'tmpdir'->'tmp_path' Rename this variables reflecting the migrations made with 3bcd316f0 and ed658d682 --- testing/test_collection.py | 50 ++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/testing/test_collection.py b/testing/test_collection.py index 3dd9283ec..cf34ef118 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 Path(str(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,9 +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(): + tmp_path = pytester.path + x = ensure_file(tmp_path / "x.py") + with tmp_path.cwd(): config = pytester.parseconfigure(x) col = pytester.getnode(config, x) assert isinstance(col, pytest.Module) @@ -645,8 +647,8 @@ class Test_getinitialnodes: The parent chain should match: Module -> Package -> 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(): From c9bb4c418f889820f786cbf8e63cbc057c653399 Mon Sep 17 00:00:00 2001 From: Matthew Hughes Date: Sun, 21 Feb 2021 13:10:00 +0000 Subject: [PATCH 3/4] fixup! Rename variables 'tmpdir'->'tmp_path' * Add some more of these * Also reintroduce+rename instances of fixture usages that were 'tmpdir'->'tmp_path' --- testing/python/collect.py | 2 +- testing/python/integration.py | 2 +- testing/test_conftest.py | 14 +++++++------- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/testing/python/collect.py b/testing/python/collect.py index 22ac6464b..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): + def __call__(self, tmp_path): 0/0 test_a = A() diff --git a/testing/python/integration.py b/testing/python/integration.py index 77ebfa23e..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): + 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_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() From 514f8e068080b374b470f6c9f349c48edfc0d3d8 Mon Sep 17 00:00:00 2001 From: Matthew Hughes Date: Wed, 24 Feb 2021 20:55:35 +0000 Subject: [PATCH 4/4] fixup! Rename variables 'tmpdir'->'tmp_path' --- testing/test_collection.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/testing/test_collection.py b/testing/test_collection.py index cf34ef118..9060ef36c 100644 --- a/testing/test_collection.py +++ b/testing/test_collection.py @@ -136,7 +136,7 @@ class TestCollectFS: 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 Path(str(tmp_path)).rglob("test_*.py"): + for x in tmp_path.rglob("test_*.py"): x.write_text("def test_hello(): pass", "utf-8") result = pytester.runpytest("--collect-only") @@ -632,8 +632,7 @@ class Test_getinitialnodes: def test_global_file(self, pytester: Pytester) -> None: tmp_path = pytester.path x = ensure_file(tmp_path / "x.py") - with tmp_path.cwd(): - config = pytester.parseconfigure(x) + config = pytester.parseconfigure(x) col = pytester.getnode(config, x) assert isinstance(col, pytest.Module) assert col.name == "x.py"