diff --git a/_pytest/fixtures.py b/_pytest/fixtures.py index 3a1321664..f71f35768 100644 --- a/_pytest/fixtures.py +++ b/_pytest/fixtures.py @@ -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 diff --git a/_pytest/junitxml.py b/_pytest/junitxml.py index ed3ba2e9a..7fb40dc35 100644 --- a/_pytest/junitxml.py +++ b/_pytest/junitxml.py @@ -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 diff --git a/_pytest/main.py b/_pytest/main.py index 4bddf1e2d..91083c85f 100644 --- a/_pytest/main.py +++ b/_pytest/main.py @@ -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 diff --git a/_pytest/nodes.py b/_pytest/nodes.py index c28c63180..7b6b695b5 100644 --- a/_pytest/nodes.py +++ b/_pytest/nodes.py @@ -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 diff --git a/_pytest/terminal.py b/_pytest/terminal.py index bb114391d..f56b966f3 100644 --- a/_pytest/terminal.py +++ b/_pytest/terminal.py @@ -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]"