Move the generic separator to a constant

This commit is contained in:
Tom Dalton 2017-10-24 10:42:16 +01:00
parent 655ab0bf8b
commit 14e3a5fcb9
5 changed files with 17 additions and 11 deletions

View File

@ -8,6 +8,7 @@ import py
from py._code.code import FormattedExcinfo
import _pytest
from _pytest import nodes
from _pytest._code.code import TerminalRepr
from _pytest.compat import (
NOTSET, exc_clear, _format_args,
@ -17,7 +18,6 @@ from _pytest.compat import (
safe_getattr,
FuncargnamesCompatAttr,
)
from _pytest.nodes import ischildnode
from _pytest.outcomes import fail, TEST_OUTCOME
@ -983,8 +983,8 @@ class FixtureManager:
# by their test id)
if p.basename.startswith("conftest.py"):
nodeid = p.dirpath().relto(self.config.rootdir)
if p.sep != "/":
nodeid = nodeid.replace(p.sep, "/")
if p.sep != nodes.SEP:
nodeid = nodeid.replace(p.sep, nodes.SEP)
self.parsefactories(plugin, nodeid)
def _getautousenames(self, nodeid):
@ -1134,5 +1134,5 @@ class FixtureManager:
def _matchfactories(self, fixturedefs, nodeid):
for fixturedef in fixturedefs:
if ischildnode(fixturedef.baseid, nodeid):
if nodes.ischildnode(fixturedef.baseid, nodeid):
yield fixturedef

View File

@ -17,6 +17,7 @@ import re
import sys
import time
import pytest
from _pytest import nodes
from _pytest.config import filename_arg
# Python 2.X and 3.X compatibility
@ -252,7 +253,7 @@ def mangle_test_address(address):
except ValueError:
pass
# convert file path to dotted path
names[0] = names[0].replace("/", '.')
names[0] = names[0].replace(nodes.SEP, '.')
names[0] = _py_ext_re.sub("", names[0])
# put any params back
names[-1] += possible_open_bracket + params

View File

@ -6,6 +6,7 @@ import os
import sys
import _pytest
from _pytest import nodes
import _pytest._code
import py
try:
@ -14,8 +15,8 @@ except ImportError:
from UserDict import DictMixin as MappingMixin
from _pytest.config import directory_arg, UsageError, hookimpl
from _pytest.runner import collect_one_node
from _pytest.outcomes import exit
from _pytest.runner import collect_one_node
tracebackcutdir = py.path.local(_pytest.__file__).dirpath()
@ -516,14 +517,14 @@ class FSCollector(Collector):
rel = fspath.relto(parent.fspath)
if rel:
name = rel
name = name.replace(os.sep, "/")
name = name.replace(os.sep, nodes.SEP)
super(FSCollector, self).__init__(name, parent, config, session)
self.fspath = fspath
def _makeid(self):
relpath = self.fspath.relto(self.config.rootdir)
if os.sep != "/":
relpath = relpath.replace(os.sep, "/")
if os.sep != nodes.SEP:
relpath = relpath.replace(os.sep, nodes.SEP)
return relpath

View File

@ -1,6 +1,9 @@
import py
SEP = "/"
def _splitnode(nodeid):
"""Split a nodeid into constituent 'parts'.
@ -19,7 +22,7 @@ def _splitnode(nodeid):
if nodeid == '':
# If there is no root node at all, return an empty list so the caller's logic can remain sane
return []
parts = nodeid.split(py.path.local.sep)
parts = nodeid.split(SEP)
# Replace single last element 'test_foo.py::Bar::()' with multiple elements 'test_foo.py', 'Bar', '()'
parts[-1:] = parts[-1].split("::")
return parts

View File

@ -13,6 +13,7 @@ import sys
import time
import platform
from _pytest import nodes
import _pytest._pluggy as pluggy
@ -452,7 +453,7 @@ class TerminalReporter:
if fspath:
res = mkrel(nodeid).replace("::()", "") # parens-normalization
if nodeid.split("::")[0] != fspath.replace("\\", "/"):
if nodeid.split("::")[0] != fspath.replace("\\", nodes.SEP):
res += " <- " + self.startdir.bestrelpath(fspath)
else:
res = "[location]"