Remove yet more unnecessary py.path uses
This commit is contained in:
		
							parent
							
								
									fe215bda6b
								
							
						
					
					
						commit
						e515264eb1
					
				| 
						 | 
					@ -670,7 +670,7 @@ class FixtureRequest:
 | 
				
			||||||
                    "\n\nRequested here:\n{}:{}".format(
 | 
					                    "\n\nRequested here:\n{}:{}".format(
 | 
				
			||||||
                        funcitem.nodeid,
 | 
					                        funcitem.nodeid,
 | 
				
			||||||
                        fixturedef.argname,
 | 
					                        fixturedef.argname,
 | 
				
			||||||
                        getlocation(fixturedef.func, funcitem.config.rootdir),
 | 
					                        getlocation(fixturedef.func, funcitem.config.rootpath),
 | 
				
			||||||
                        source_path_str,
 | 
					                        source_path_str,
 | 
				
			||||||
                        source_lineno,
 | 
					                        source_lineno,
 | 
				
			||||||
                    )
 | 
					                    )
 | 
				
			||||||
| 
						 | 
					@ -728,7 +728,7 @@ class FixtureRequest:
 | 
				
			||||||
            fs, lineno = getfslineno(factory)
 | 
					            fs, lineno = getfslineno(factory)
 | 
				
			||||||
            if isinstance(fs, Path):
 | 
					            if isinstance(fs, Path):
 | 
				
			||||||
                session: Session = self._pyfuncitem.session
 | 
					                session: Session = self._pyfuncitem.session
 | 
				
			||||||
                p = bestrelpath(Path(session.fspath), fs)
 | 
					                p = bestrelpath(session.path, fs)
 | 
				
			||||||
            else:
 | 
					            else:
 | 
				
			||||||
                p = fs
 | 
					                p = fs
 | 
				
			||||||
            args = _format_args(factory)
 | 
					            args = _format_args(factory)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -32,6 +32,7 @@ from _pytest.mark.structures import MarkDecorator
 | 
				
			||||||
from _pytest.mark.structures import NodeKeywords
 | 
					from _pytest.mark.structures import NodeKeywords
 | 
				
			||||||
from _pytest.outcomes import fail
 | 
					from _pytest.outcomes import fail
 | 
				
			||||||
from _pytest.pathlib import absolutepath
 | 
					from _pytest.pathlib import absolutepath
 | 
				
			||||||
 | 
					from _pytest.pathlib import commonpath
 | 
				
			||||||
from _pytest.store import Store
 | 
					from _pytest.store import Store
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if TYPE_CHECKING:
 | 
					if TYPE_CHECKING:
 | 
				
			||||||
| 
						 | 
					@ -517,13 +518,11 @@ class Collector(Node):
 | 
				
			||||||
            excinfo.traceback = ntraceback.filter()
 | 
					            excinfo.traceback = ntraceback.filter()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def _check_initialpaths_for_relpath(
 | 
					def _check_initialpaths_for_relpath(session: "Session", path: Path) -> Optional[str]:
 | 
				
			||||||
    session: "Session", fspath: LEGACY_PATH
 | 
					 | 
				
			||||||
) -> Optional[str]:
 | 
					 | 
				
			||||||
    for initial_path in session._initialpaths:
 | 
					    for initial_path in session._initialpaths:
 | 
				
			||||||
        initial_path_ = legacy_path(initial_path)
 | 
					        if commonpath(path, initial_path) == initial_path:
 | 
				
			||||||
        if fspath.common(initial_path_) == initial_path_:
 | 
					            rel = str(path.relative_to(initial_path))
 | 
				
			||||||
            return fspath.relto(initial_path_)
 | 
					            return "" if rel == "." else rel
 | 
				
			||||||
    return None
 | 
					    return None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -538,7 +537,7 @@ class FSCollector(Collector):
 | 
				
			||||||
        nodeid: Optional[str] = None,
 | 
					        nodeid: Optional[str] = None,
 | 
				
			||||||
    ) -> None:
 | 
					    ) -> None:
 | 
				
			||||||
        path, fspath = _imply_path(path, fspath=fspath)
 | 
					        path, fspath = _imply_path(path, fspath=fspath)
 | 
				
			||||||
        name = fspath.basename
 | 
					        name = path.name
 | 
				
			||||||
        if parent is not None and parent.path != path:
 | 
					        if parent is not None and parent.path != path:
 | 
				
			||||||
            try:
 | 
					            try:
 | 
				
			||||||
                rel = path.relative_to(parent.path)
 | 
					                rel = path.relative_to(parent.path)
 | 
				
			||||||
| 
						 | 
					@ -547,7 +546,7 @@ class FSCollector(Collector):
 | 
				
			||||||
            else:
 | 
					            else:
 | 
				
			||||||
                name = str(rel)
 | 
					                name = str(rel)
 | 
				
			||||||
            name = name.replace(os.sep, SEP)
 | 
					            name = name.replace(os.sep, SEP)
 | 
				
			||||||
        self.path = Path(fspath)
 | 
					        self.path = path
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        session = session or parent.session
 | 
					        session = session or parent.session
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -555,7 +554,7 @@ class FSCollector(Collector):
 | 
				
			||||||
            try:
 | 
					            try:
 | 
				
			||||||
                nodeid = str(self.path.relative_to(session.config.rootpath))
 | 
					                nodeid = str(self.path.relative_to(session.config.rootpath))
 | 
				
			||||||
            except ValueError:
 | 
					            except ValueError:
 | 
				
			||||||
                nodeid = _check_initialpaths_for_relpath(session, fspath)
 | 
					                nodeid = _check_initialpaths_for_relpath(session, path)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if nodeid and os.sep != SEP:
 | 
					            if nodeid and os.sep != SEP:
 | 
				
			||||||
                nodeid = nodeid.replace(os.sep, SEP)
 | 
					                nodeid = nodeid.replace(os.sep, SEP)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -645,7 +645,7 @@ class Package(Module):
 | 
				
			||||||
            session=session,
 | 
					            session=session,
 | 
				
			||||||
            nodeid=nodeid,
 | 
					            nodeid=nodeid,
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
        self.name = os.path.basename(str(fspath.dirname))
 | 
					        self.name = path.parent.name
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def setup(self) -> None:
 | 
					    def setup(self) -> None:
 | 
				
			||||||
        # Not using fixtures to call setup_module here because autouse fixtures
 | 
					        # Not using fixtures to call setup_module here because autouse fixtures
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -933,11 +933,11 @@ def test_setup_only_available_in_subdir(pytester: Pytester) -> None:
 | 
				
			||||||
            """\
 | 
					            """\
 | 
				
			||||||
            import pytest
 | 
					            import pytest
 | 
				
			||||||
            def pytest_runtest_setup(item):
 | 
					            def pytest_runtest_setup(item):
 | 
				
			||||||
                assert item.fspath.purebasename == "test_in_sub1"
 | 
					                assert item.path.stem == "test_in_sub1"
 | 
				
			||||||
            def pytest_runtest_call(item):
 | 
					            def pytest_runtest_call(item):
 | 
				
			||||||
                assert item.fspath.purebasename == "test_in_sub1"
 | 
					                assert item.path.stem == "test_in_sub1"
 | 
				
			||||||
            def pytest_runtest_teardown(item):
 | 
					            def pytest_runtest_teardown(item):
 | 
				
			||||||
                assert item.fspath.purebasename == "test_in_sub1"
 | 
					                assert item.path.stem == "test_in_sub1"
 | 
				
			||||||
            """
 | 
					            """
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
| 
						 | 
					@ -946,11 +946,11 @@ def test_setup_only_available_in_subdir(pytester: Pytester) -> None:
 | 
				
			||||||
            """\
 | 
					            """\
 | 
				
			||||||
            import pytest
 | 
					            import pytest
 | 
				
			||||||
            def pytest_runtest_setup(item):
 | 
					            def pytest_runtest_setup(item):
 | 
				
			||||||
                assert item.fspath.purebasename == "test_in_sub2"
 | 
					                assert item.path.stem == "test_in_sub2"
 | 
				
			||||||
            def pytest_runtest_call(item):
 | 
					            def pytest_runtest_call(item):
 | 
				
			||||||
                assert item.fspath.purebasename == "test_in_sub2"
 | 
					                assert item.path.stem == "test_in_sub2"
 | 
				
			||||||
            def pytest_runtest_teardown(item):
 | 
					            def pytest_runtest_teardown(item):
 | 
				
			||||||
                assert item.fspath.purebasename == "test_in_sub2"
 | 
					                assert item.path.stem == "test_in_sub2"
 | 
				
			||||||
            """
 | 
					            """
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
| 
						 | 
					@ -1125,8 +1125,7 @@ class TestReportInfo:
 | 
				
			||||||
    def test_func_reportinfo(self, pytester: Pytester) -> None:
 | 
					    def test_func_reportinfo(self, pytester: Pytester) -> None:
 | 
				
			||||||
        item = pytester.getitem("def test_func(): pass")
 | 
					        item = pytester.getitem("def test_func(): pass")
 | 
				
			||||||
        fspath, lineno, modpath = item.reportinfo()
 | 
					        fspath, lineno, modpath = item.reportinfo()
 | 
				
			||||||
        with pytest.warns(DeprecationWarning):
 | 
					        assert str(fspath) == str(item.path)
 | 
				
			||||||
            assert fspath == item.fspath
 | 
					 | 
				
			||||||
        assert lineno == 0
 | 
					        assert lineno == 0
 | 
				
			||||||
        assert modpath == "test_func"
 | 
					        assert modpath == "test_func"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1141,8 +1140,7 @@ class TestReportInfo:
 | 
				
			||||||
        classcol = pytester.collect_by_name(modcol, "TestClass")
 | 
					        classcol = pytester.collect_by_name(modcol, "TestClass")
 | 
				
			||||||
        assert isinstance(classcol, Class)
 | 
					        assert isinstance(classcol, Class)
 | 
				
			||||||
        fspath, lineno, msg = classcol.reportinfo()
 | 
					        fspath, lineno, msg = classcol.reportinfo()
 | 
				
			||||||
        with pytest.warns(DeprecationWarning):
 | 
					        assert str(fspath) == str(modcol.path)
 | 
				
			||||||
            assert fspath == modcol.fspath
 | 
					 | 
				
			||||||
        assert lineno == 1
 | 
					        assert lineno == 1
 | 
				
			||||||
        assert msg == "TestClass"
 | 
					        assert msg == "TestClass"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -5,7 +5,6 @@ from typing import Type
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import pytest
 | 
					import pytest
 | 
				
			||||||
from _pytest import nodes
 | 
					from _pytest import nodes
 | 
				
			||||||
from _pytest.compat import legacy_path
 | 
					 | 
				
			||||||
from _pytest.pytester import Pytester
 | 
					from _pytest.pytester import Pytester
 | 
				
			||||||
from _pytest.warning_types import PytestWarning
 | 
					from _pytest.warning_types import PytestWarning
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -76,7 +75,7 @@ def test__check_initialpaths_for_relpath() -> None:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    session = cast(pytest.Session, FakeSession1)
 | 
					    session = cast(pytest.Session, FakeSession1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    assert nodes._check_initialpaths_for_relpath(session, legacy_path(cwd)) == ""
 | 
					    assert nodes._check_initialpaths_for_relpath(session, cwd) == ""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    sub = cwd / "file"
 | 
					    sub = cwd / "file"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -85,9 +84,9 @@ def test__check_initialpaths_for_relpath() -> None:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    session = cast(pytest.Session, FakeSession2)
 | 
					    session = cast(pytest.Session, FakeSession2)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    assert nodes._check_initialpaths_for_relpath(session, legacy_path(sub)) == "file"
 | 
					    assert nodes._check_initialpaths_for_relpath(session, sub) == "file"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    outside = legacy_path("/outside")
 | 
					    outside = Path("/outside")
 | 
				
			||||||
    assert nodes._check_initialpaths_for_relpath(session, outside) is None
 | 
					    assert nodes._check_initialpaths_for_relpath(session, outside) is None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue