Skip to content

Commit

Permalink
Use _is_same function
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoddemus committed Feb 17, 2024
1 parent abb43a6 commit 7b04075
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
7 changes: 2 additions & 5 deletions src/_pytest/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from _pytest.config.argparsing import Parser
from _pytest.fixtures import FixtureManager
from _pytest.outcomes import exit
from _pytest.pathlib import _is_same
from _pytest.pathlib import absolutepath
from _pytest.pathlib import bestrelpath
from _pytest.pathlib import fnmatch_ex
Expand Down Expand Up @@ -900,11 +901,7 @@ def collect(self) -> Iterator[Union[nodes.Item, nodes.Collector]]:
for node in reversed(subnodes):
# Path part e.g. `/a/b/` in `/a/b/test_file.py::TestIt::test_it`.
if isinstance(matchparts[0], Path):
is_match = node.path == matchparts[0]
if sys.platform == "win32" and not is_match:
# In case the file paths do not match, fallback to samefile() to
# account for short-paths on Windows (#11895).
is_match = os.path.samefile(node.path, matchparts[0])
is_match = _is_same(node.path, matchparts[0])
# Name part e.g. `TestIt` in `/a/b/test_file.py::TestIt::test_it`.
else:
# TODO: Remove parametrized workaround once collection structure contains
Expand Down
4 changes: 2 additions & 2 deletions src/_pytest/pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,12 +596,12 @@ def import_path(
# compare equal, to circumvent os.path.samefile returning False for mounts in UNC (#7678).
if sys.platform.startswith("win"):

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

else:

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


Expand Down

0 comments on commit 7b04075

Please sign in to comment.