From fefac6607931f938074d4830e25c1e0682645fae Mon Sep 17 00:00:00 2001 From: holger krekel Date: Sun, 7 Nov 2010 12:05:32 +0100 Subject: [PATCH] remove duplicate code, normalize relative path names to fix windows running tests --- pytest/plugin/junitxml.py | 2 +- pytest/plugin/python.py | 1 + pytest/plugin/session.py | 41 +++++++++++---------------------------- 3 files changed, 13 insertions(+), 31 deletions(-) diff --git a/pytest/plugin/junitxml.py b/pytest/plugin/junitxml.py index 795dea03a..c6da0ad18 100644 --- a/pytest/plugin/junitxml.py +++ b/pytest/plugin/junitxml.py @@ -39,7 +39,7 @@ class LogXML(object): def _opentestcase(self, report): names = report.nodeid.split("::") - names[0] = names[0].replace(os.sep, '.') + names[0] = names[0].replace("/", '.') names = tuple(names) d = {'time': self._durations.pop(names, "0")} names = [x.replace(".py", "") for x in names if x != "()"] diff --git a/pytest/plugin/python.py b/pytest/plugin/python.py index 6399a3011..c4472fa9d 100644 --- a/pytest/plugin/python.py +++ b/pytest/plugin/python.py @@ -354,6 +354,7 @@ class Generator(FunctionMixin, PyCollectorMixin, pytest.collect.Collector): # invoke setup/teardown on popular request # (induced by the common "test_*" naming shared with normal tests) self.config._setupstate.prepare(self) + l = [] seen = {} for i, x in enumerate(self.obj()): diff --git a/pytest/plugin/session.py b/pytest/plugin/session.py index 8645e4315..b5624d5bf 100644 --- a/pytest/plugin/session.py +++ b/pytest/plugin/session.py @@ -108,34 +108,6 @@ def pytest_ignore_collect(path, config): ignore_paths.extend([py.path.local(x) for x in excludeopt]) return path in ignore_paths -class Session(object): - class Interrupted(KeyboardInterrupt): - """ signals an interrupted test run. """ - __module__ = 'builtins' # for py3 - - def __init__(self, config): - self.config = config - self.config.pluginmanager.register(self, name="session", prepend=True) - self._testsfailed = 0 - self.shouldstop = False - self.session = Session(config) # XXX move elswehre - - def pytest_collectstart(self): - if self.shouldstop: - raise self.Interrupted(self.shouldstop) - - def pytest_runtest_logreport(self, report): - if report.failed and 'xfail' not in getattr(report, 'keywords', []): - self._testsfailed += 1 - maxfail = self.config.getvalue("maxfail") - if maxfail and self._testsfailed >= maxfail: - self.shouldstop = "stopping after %d failures" % ( - self._testsfailed) - pytest_collectreport = pytest_runtest_logreport - -class NoMatch(Exception): - """ raised if matching cannot locate a matching names. """ - class HookProxy: def __init__(self, fspath, config): self.fspath = fspath @@ -311,7 +283,12 @@ class Collector(Node): class FSCollector(Collector): def __init__(self, fspath, parent=None, config=None, session=None): fspath = py.path.local(fspath) # xxx only for test_resultlog.py? - name = parent and fspath.relto(parent.fspath) or fspath.basename + name = fspath.basename + if parent is not None: + rel = fspath.relto(parent.fspath) + if rel: + name = rel + name = name.replace(os.sep, "/") super(FSCollector, self).__init__(name, parent, config, session) self.fspath = fspath @@ -343,6 +320,9 @@ class Item(Node): self._location = location return location +class NoMatch(Exception): + """ raised if matching cannot locate a matching names. """ + class Session(FSCollector): class Interrupted(KeyboardInterrupt): """ signals an interrupted test run. """ @@ -469,7 +449,8 @@ class Session(FSCollector): if self.config.option.pyargs: arg = self._tryconvertpyarg(arg) parts = str(arg).split("::") - path = self.fspath.join(parts[0], abs=True) + relpath = parts[0].replace("/", os.sep) + path = self.fspath.join(relpath, abs=True) if not path.check(): if self.config.option.pyargs: msg = "file or package not found: "