Skip to content

Commit 7b04075

Browse files
committed
Use _is_same function
1 parent abb43a6 commit 7b04075

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

src/_pytest/main.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
from _pytest.config.argparsing import Parser
3838
from _pytest.fixtures import FixtureManager
3939
from _pytest.outcomes import exit
40+
from _pytest.pathlib import _is_same
4041
from _pytest.pathlib import absolutepath
4142
from _pytest.pathlib import bestrelpath
4243
from _pytest.pathlib import fnmatch_ex
@@ -900,11 +901,7 @@ def collect(self) -> Iterator[Union[nodes.Item, nodes.Collector]]:
900901
for node in reversed(subnodes):
901902
# Path part e.g. `/a/b/` in `/a/b/test_file.py::TestIt::test_it`.
902903
if isinstance(matchparts[0], Path):
903-
is_match = node.path == matchparts[0]
904-
if sys.platform == "win32" and not is_match:
905-
# In case the file paths do not match, fallback to samefile() to
906-
# account for short-paths on Windows (#11895).
907-
is_match = os.path.samefile(node.path, matchparts[0])
904+
is_match = _is_same(node.path, matchparts[0])
908905
# Name part e.g. `TestIt` in `/a/b/test_file.py::TestIt::test_it`.
909906
else:
910907
# TODO: Remove parametrized workaround once collection structure contains

src/_pytest/pathlib.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -596,12 +596,12 @@ def import_path(
596596
# compare equal, to circumvent os.path.samefile returning False for mounts in UNC (#7678).
597597
if sys.platform.startswith("win"):
598598

599-
def _is_same(f1: str, f2: str) -> bool:
599+
def _is_same(f1: Union[Path, str], f2: Union[Path, str]) -> bool:
600600
return Path(f1) == Path(f2) or os.path.samefile(f1, f2)
601601

602602
else:
603603

604-
def _is_same(f1: str, f2: str) -> bool:
604+
def _is_same(f1: Union[Path, str], f2: Union[Path, str]) -> bool:
605605
return os.path.samefile(f1, f2)
606606

607607

0 commit comments

Comments
 (0)