[py-svn] pytest commit ea0185ce5bed: remove duplicate code, normalize relative path names to fix windows running tests

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Sun Nov 7 12:04:00 CET 2010


# HG changeset patch -- Bitbucket.org
# Project pytest
# URL http://bitbucket.org/hpk42/pytest/overview
# User holger krekel <holger at merlinux.eu>
# Date 1289127932 -3600
# Node ID ea0185ce5bed6006371bb2b878203aa075b5d45e
# Parent  6a5bbc78bad973e969317db8b86f151e6539c42e
remove duplicate code, normalize relative path names to fix windows running tests

--- 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 != "()"]

--- a/pytest/plugin/python.py
+++ b/pytest/plugin/python.py
@@ -354,6 +354,7 @@ class Generator(FunctionMixin, PyCollect
         # 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()):

--- 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: "



More information about the pytest-commit mailing list