Merge pull request #8357 from matthewhughes934/remove-tmpdir-from-tests
Remove tmpdir from tests
This commit is contained in:
		
						commit
						6e7dc8bac8
					
				| 
						 | 
					@ -286,9 +286,7 @@ def test_deindent() -> None:
 | 
				
			||||||
    assert lines == ["def f():", "    def g():", "        pass"]
 | 
					    assert lines == ["def f():", "    def g():", "        pass"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def test_source_of_class_at_eof_without_newline(
 | 
					def test_source_of_class_at_eof_without_newline(_sys_snapshot, tmp_path: Path) -> None:
 | 
				
			||||||
    tmpdir, _sys_snapshot, tmp_path: Path
 | 
					 | 
				
			||||||
) -> None:
 | 
					 | 
				
			||||||
    # this test fails because the implicit inspect.getsource(A) below
 | 
					    # this test fails because the implicit inspect.getsource(A) below
 | 
				
			||||||
    # does not return the "x = 1" last line.
 | 
					    # does not return the "x = 1" last line.
 | 
				
			||||||
    source = Source(
 | 
					    source = Source(
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -274,7 +274,7 @@ class TestFunction:
 | 
				
			||||||
        pytester.makepyfile(
 | 
					        pytester.makepyfile(
 | 
				
			||||||
            """
 | 
					            """
 | 
				
			||||||
            class A(object):
 | 
					            class A(object):
 | 
				
			||||||
                def __call__(self, tmpdir):
 | 
					                def __call__(self, tmp_path):
 | 
				
			||||||
                    0/0
 | 
					                    0/0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            test_a = A()
 | 
					            test_a = A()
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -234,7 +234,7 @@ class TestMockDecoration:
 | 
				
			||||||
            @mock.patch("os.path.abspath")
 | 
					            @mock.patch("os.path.abspath")
 | 
				
			||||||
            @mock.patch("os.path.normpath")
 | 
					            @mock.patch("os.path.normpath")
 | 
				
			||||||
            @mock.patch("os.path.basename", new=mock_basename)
 | 
					            @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"
 | 
					                abspath.return_value = "this"
 | 
				
			||||||
                os.path.normpath(os.path.abspath("hello"))
 | 
					                os.path.normpath(os.path.abspath("hello"))
 | 
				
			||||||
                normpath.assert_any_call("this")
 | 
					                normpath.assert_any_call("this")
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -127,16 +127,16 @@ class TestCollector:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class TestCollectFS:
 | 
					class TestCollectFS:
 | 
				
			||||||
    def test_ignored_certain_directories(self, pytester: Pytester) -> None:
 | 
					    def test_ignored_certain_directories(self, pytester: Pytester) -> None:
 | 
				
			||||||
        tmpdir = pytester.path
 | 
					        tmp_path = pytester.path
 | 
				
			||||||
        ensure_file(tmpdir / "build" / "test_notfound.py")
 | 
					        ensure_file(tmp_path / "build" / "test_notfound.py")
 | 
				
			||||||
        ensure_file(tmpdir / "dist" / "test_notfound.py")
 | 
					        ensure_file(tmp_path / "dist" / "test_notfound.py")
 | 
				
			||||||
        ensure_file(tmpdir / "_darcs" / "test_notfound.py")
 | 
					        ensure_file(tmp_path / "_darcs" / "test_notfound.py")
 | 
				
			||||||
        ensure_file(tmpdir / "CVS" / "test_notfound.py")
 | 
					        ensure_file(tmp_path / "CVS" / "test_notfound.py")
 | 
				
			||||||
        ensure_file(tmpdir / "{arch}" / "test_notfound.py")
 | 
					        ensure_file(tmp_path / "{arch}" / "test_notfound.py")
 | 
				
			||||||
        ensure_file(tmpdir / ".whatever" / "test_notfound.py")
 | 
					        ensure_file(tmp_path / ".whatever" / "test_notfound.py")
 | 
				
			||||||
        ensure_file(tmpdir / ".bzr" / "test_notfound.py")
 | 
					        ensure_file(tmp_path / ".bzr" / "test_notfound.py")
 | 
				
			||||||
        ensure_file(tmpdir / "normal" / "test_found.py")
 | 
					        ensure_file(tmp_path / "normal" / "test_found.py")
 | 
				
			||||||
        for x in Path(str(tmpdir)).rglob("test_*.py"):
 | 
					        for x in tmp_path.rglob("test_*.py"):
 | 
				
			||||||
            x.write_text("def test_hello(): pass", "utf-8")
 | 
					            x.write_text("def test_hello(): pass", "utf-8")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        result = pytester.runpytest("--collect-only")
 | 
					        result = pytester.runpytest("--collect-only")
 | 
				
			||||||
| 
						 | 
					@ -226,10 +226,12 @@ class TestCollectFS:
 | 
				
			||||||
            norecursedirs = mydir xyz*
 | 
					            norecursedirs = mydir xyz*
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
        tmpdir = pytester.path
 | 
					        tmp_path = pytester.path
 | 
				
			||||||
        ensure_file(tmpdir / "mydir" / "test_hello.py").write_text("def test_1(): pass")
 | 
					        ensure_file(tmp_path / "mydir" / "test_hello.py").write_text(
 | 
				
			||||||
        ensure_file(tmpdir / "xyz123" / "test_2.py").write_text("def test_2(): 0/0")
 | 
					            "def test_1(): pass"
 | 
				
			||||||
        ensure_file(tmpdir / "xy" / "test_ok.py").write_text("def test_3(): 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 = pytester.inline_run()
 | 
				
			||||||
        rec.assertoutcome(passed=1)
 | 
					        rec.assertoutcome(passed=1)
 | 
				
			||||||
        rec = pytester.inline_run("xyz123/test_2.py")
 | 
					        rec = pytester.inline_run("xyz123/test_2.py")
 | 
				
			||||||
| 
						 | 
					@ -242,10 +244,10 @@ class TestCollectFS:
 | 
				
			||||||
            testpaths = gui uts
 | 
					            testpaths = gui uts
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
        tmpdir = pytester.path
 | 
					        tmp_path = pytester.path
 | 
				
			||||||
        ensure_file(tmpdir / "env" / "test_1.py").write_text("def test_env(): pass")
 | 
					        ensure_file(tmp_path / "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(tmp_path / "gui" / "test_2.py").write_text("def test_gui(): pass")
 | 
				
			||||||
        ensure_file(tmpdir / "uts" / "test_3.py").write_text("def test_uts(): pass")
 | 
					        ensure_file(tmp_path / "uts" / "test_3.py").write_text("def test_uts(): pass")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # executing from rootdir only tests from `testpaths` directories
 | 
					        # executing from rootdir only tests from `testpaths` directories
 | 
				
			||||||
        # are collected
 | 
					        # are collected
 | 
				
			||||||
| 
						 | 
					@ -255,7 +257,7 @@ class TestCollectFS:
 | 
				
			||||||
        # check that explicitly passing directories in the command-line
 | 
					        # check that explicitly passing directories in the command-line
 | 
				
			||||||
        # collects the tests
 | 
					        # collects the tests
 | 
				
			||||||
        for dirname in ("env", "gui", "uts"):
 | 
					        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]
 | 
					            assert [x.name for x in items] == ["test_%s" % dirname]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # changing cwd to each subdirectory and running pytest without
 | 
					        # changing cwd to each subdirectory and running pytest without
 | 
				
			||||||
| 
						 | 
					@ -628,10 +630,9 @@ class TestSession:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Test_getinitialnodes:
 | 
					class Test_getinitialnodes:
 | 
				
			||||||
    def test_global_file(self, pytester: Pytester) -> None:
 | 
					    def test_global_file(self, pytester: Pytester) -> None:
 | 
				
			||||||
        tmpdir = pytester.path
 | 
					        tmp_path = pytester.path
 | 
				
			||||||
        x = ensure_file(tmpdir / "x.py")
 | 
					        x = ensure_file(tmp_path / "x.py")
 | 
				
			||||||
        with tmpdir.cwd():
 | 
					        config = pytester.parseconfigure(x)
 | 
				
			||||||
            config = pytester.parseconfigure(x)
 | 
					 | 
				
			||||||
        col = pytester.getnode(config, x)
 | 
					        col = pytester.getnode(config, x)
 | 
				
			||||||
        assert isinstance(col, pytest.Module)
 | 
					        assert isinstance(col, pytest.Module)
 | 
				
			||||||
        assert col.name == "x.py"
 | 
					        assert col.name == "x.py"
 | 
				
			||||||
| 
						 | 
					@ -645,8 +646,8 @@ class Test_getinitialnodes:
 | 
				
			||||||
        The parent chain should match: Module<x.py> -> Package<subdir> -> Session.
 | 
					        The parent chain should match: Module<x.py> -> Package<subdir> -> Session.
 | 
				
			||||||
            Session's parent should always be None.
 | 
					            Session's parent should always be None.
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        tmpdir = pytester.path
 | 
					        tmp_path = pytester.path
 | 
				
			||||||
        subdir = tmpdir.joinpath("subdir")
 | 
					        subdir = tmp_path.joinpath("subdir")
 | 
				
			||||||
        x = ensure_file(subdir / "x.py")
 | 
					        x = ensure_file(subdir / "x.py")
 | 
				
			||||||
        ensure_file(subdir / "__init__.py")
 | 
					        ensure_file(subdir / "__init__.py")
 | 
				
			||||||
        with subdir.cwd():
 | 
					        with subdir.cwd():
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -44,15 +44,15 @@ class TestConftestValueAccessGlobal:
 | 
				
			||||||
    def basedir(
 | 
					    def basedir(
 | 
				
			||||||
        self, request, tmp_path_factory: TempPathFactory
 | 
					        self, request, tmp_path_factory: TempPathFactory
 | 
				
			||||||
    ) -> Generator[Path, None, None]:
 | 
					    ) -> Generator[Path, None, None]:
 | 
				
			||||||
        tmpdir = tmp_path_factory.mktemp("basedir", numbered=True)
 | 
					        tmp_path = tmp_path_factory.mktemp("basedir", numbered=True)
 | 
				
			||||||
        tmpdir.joinpath("adir/b").mkdir(parents=True)
 | 
					        tmp_path.joinpath("adir/b").mkdir(parents=True)
 | 
				
			||||||
        tmpdir.joinpath("adir/conftest.py").write_text("a=1 ; Directory = 3")
 | 
					        tmp_path.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.joinpath("adir/b/conftest.py").write_text("b=2 ; a = 1.5")
 | 
				
			||||||
        if request.param == "inpackage":
 | 
					        if request.param == "inpackage":
 | 
				
			||||||
            tmpdir.joinpath("adir/__init__.py").touch()
 | 
					            tmp_path.joinpath("adir/__init__.py").touch()
 | 
				
			||||||
            tmpdir.joinpath("adir/b/__init__.py").touch()
 | 
					            tmp_path.joinpath("adir/b/__init__.py").touch()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        yield tmpdir
 | 
					        yield tmp_path
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_basic_init(self, basedir: Path) -> None:
 | 
					    def test_basic_init(self, basedir: Path) -> None:
 | 
				
			||||||
        conftest = PytestPluginManager()
 | 
					        conftest = PytestPluginManager()
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue