[py-svn] pytest commit 73811fb299b8: fix doctest IDs, also fix tree traversal and remove dead code

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Wed Nov 17 18:26:04 CET 2010


# HG changeset patch -- Bitbucket.org
# Project pytest
# URL http://bitbucket.org/hpk42/pytest/overview
# User holger krekel <holger at merlinux.eu>
# Date 1290014668 -3600
# Node ID 73811fb299b8711440299d096f576bbc7f344139
# Parent  2dea0dd5657ef31ef68cad10a4b356a29db500c8
fix doctest IDs, also fix tree traversal and remove dead code

--- a/_pytest/doctest.py
+++ b/_pytest/doctest.py
@@ -33,11 +33,6 @@ class ReprFailDoctest(TerminalRepr):
         self.reprlocation.toterminal(tw)
 
 class DoctestItem(pytest.Item):
-    def __init__(self, path, parent):
-        name = self.__class__.__name__ + ":" + path.basename
-        super(DoctestItem, self).__init__(name=name, parent=parent)
-        self.fspath = path
-
     def repr_failure(self, excinfo):
         if excinfo.errisinstance(py.std.doctest.DocTestFailure):
             doctestfailure = excinfo.value
@@ -67,13 +62,13 @@ class DoctestItem(pytest.Item):
     def reportinfo(self):
         return self.fspath, None, "[doctest]"
 
-class DoctestTextfile(DoctestItem):
+class DoctestTextfile(DoctestItem, pytest.File):
     def runtest(self):
         failed, tot = py.std.doctest.testfile(
             str(self.fspath), module_relative=False,
             raise_on_error=True, verbose=0)
 
-class DoctestModule(DoctestItem):
+class DoctestModule(DoctestItem, pytest.File):
     def runtest(self):
         module = self.fspath.pyimport()
         failed, tot = py.std.doctest.testmod(

--- a/_pytest/session.py
+++ b/_pytest/session.py
@@ -482,7 +482,8 @@ class Session(FSCollector):
         resultnodes = []
         for node in matching:
             if isinstance(node, pytest.Item):
-                resultnodes.append(node)
+                if not names:
+                    resultnodes.append(node)
                 continue
             assert isinstance(node, pytest.Collector)
             node.ihook.pytest_collectstart(collector=node)
@@ -508,5 +509,3 @@ class Session(FSCollector):
                     for x in self.genitems(subnode):
                         yield x
             node.ihook.pytest_collectreport(report=rep)
-
-Session = Session

--- a/testing/acceptance_test.py
+++ b/testing/acceptance_test.py
@@ -372,3 +372,22 @@ class TestInvocationVariants:
         """)
         reprec = testdir.inline_run(testpath)
         reprec.assertoutcome(passed=1)
+
+    def test_doctest_id(self, testdir):
+        testdir.makefile('.txt', """
+            >>> x=3
+            >>> x
+            4
+        """)
+        result = testdir.runpytest("-rf")
+        lines = result.stdout.str().splitlines()
+        for line in lines:
+            if line.startswith("FAIL "):
+                testid = line[5:].strip()
+                break
+        result = testdir.runpytest(testid, '-rf')
+        result.stdout.fnmatch_lines([
+            line,
+            "*1 failed*",
+        ])
+

--- a/testing/test_collection.py
+++ b/testing/test_collection.py
@@ -472,10 +472,6 @@ class TestSession:
         item2b, = newcol.perform_collect([item.nodeid], genitems=False)
         assert item2b == item2
 
-def getargnode(collection, arg):
-    argpath = arg.relto(collection.fspath)
-    return collection.perform_collect([argpath], genitems=False)[0]
-
 class Test_getinitialnodes:
     def test_global_file(self, testdir, tmpdir):
         x = tmpdir.ensure("x.py")
@@ -552,3 +548,43 @@ class Test_genitems:
         s = items[0].getmodpath(stopatmodule=False)
         assert s.endswith("test_example_items1.testone")
         print(s)
+
+def test_matchnodes_two_collections_same_file(testdir):
+    testdir.makeconftest("""
+        import pytest
+        def pytest_configure(config):
+            config.pluginmanager.register(Plugin2())
+
+        class Plugin2:
+            def pytest_collect_file(self, path, parent):
+                if path.ext == ".abc":
+                    return MyFile2(path, parent)
+
+        def pytest_collect_file(path, parent):
+            if path.ext == ".abc":
+                return MyFile1(path, parent)
+
+        class MyFile1(pytest.Item, pytest.File):
+            def runtest(self):
+                pass
+        class MyFile2(pytest.File):
+            def collect(self):
+                return [Item2("hello", parent=self)]
+
+        class Item2(pytest.Item):
+            def runtest(self):
+                pass
+    """)
+    p = testdir.makefile(".abc", "")
+    result = testdir.runpytest()
+    assert result.ret == 0
+    result.stdout.fnmatch_lines([
+        "*2 passed*",
+    ])
+    res = testdir.runpytest("%s::hello" % p.basename)
+    res.stdout.fnmatch_lines([
+        "*1 passed*",
+    ])
+    
+
+



More information about the pytest-commit mailing list