Move _uniquepath to pathlib as unique_path.

Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
This commit is contained in:
Christian Neumüller
2019-08-28 09:21:03 +02:00
parent a98270eac0
commit 29bb0eda27
3 changed files with 19 additions and 12 deletions

View File

@@ -30,16 +30,13 @@ from _pytest._code import filter_traceback
from _pytest.compat import importlib_metadata
from _pytest.outcomes import fail
from _pytest.outcomes import Skipped
from _pytest.pathlib import unique_path
from _pytest.warning_types import PytestConfigWarning
hookimpl = HookimplMarker("pytest")
hookspec = HookspecMarker("pytest")
def _uniquepath(path):
return type(path)(os.path.normcase(str(path.realpath())))
class ConftestImportFailure(Exception):
def __init__(self, path, excinfo):
Exception.__init__(self, path, excinfo)
@@ -370,7 +367,7 @@ class PytestPluginManager(PluginManager):
"""
current = py.path.local()
self._confcutdir = (
_uniquepath(current.join(namespace.confcutdir, abs=True))
unique_path(current.join(namespace.confcutdir, abs=True))
if namespace.confcutdir
else None
)
@@ -409,7 +406,7 @@ class PytestPluginManager(PluginManager):
else:
directory = path
directory = _uniquepath(directory)
directory = unique_path(directory)
# XXX these days we may rather want to use config.rootdir
# and allow users to opt into looking into the rootdir parent
@@ -438,7 +435,7 @@ class PytestPluginManager(PluginManager):
# Use realpath to avoid loading the same conftest twice
# with build systems that create build directories containing
# symlinks to actual files.
conftestpath = _uniquepath(conftestpath)
conftestpath = unique_path(conftestpath)
try:
return self._conftestpath2mod[conftestpath]
except KeyError:

View File

@@ -11,6 +11,7 @@ from functools import partial
from os.path import expanduser
from os.path import expandvars
from os.path import isabs
from os.path import normcase
from os.path import sep
from posixpath import sep as posix_sep
@@ -334,3 +335,12 @@ def fnmatch_ex(pattern, path):
def parts(s):
parts = s.split(sep)
return {sep.join(parts[: i + 1]) or sep for i in range(len(parts))}
def unique_path(path):
"""Returns a unique path in case-insensitive (but case-preserving) file
systems such as Windows.
This is needed only for ``py.path.local``; ``pathlib.Path`` handles this
natively with ``resolve()``."""
return type(path)(normcase(str(path.realpath())))