[py-svn] r56892 - in py/branch/event/py: code test2/rep test2/rep/testing test2/testing

hpk at codespeak.net hpk at codespeak.net
Fri Aug 1 13:46:32 CEST 2008


Author: hpk
Date: Fri Aug  1 13:46:29 2008
New Revision: 56892

Modified:
   py/branch/event/py/code/tbpresent.py
   py/branch/event/py/test2/rep/base.py
   py/branch/event/py/test2/rep/terminal.py
   py/branch/event/py/test2/rep/testing/test_basereporter.py
   py/branch/event/py/test2/testing/acceptance_test.py
   py/branch/event/py/test2/testing/suptest.py
Log:
* test and impl for skip related functionality
* enhancements to test setup/help machinery 
* small refactorings



Modified: py/branch/event/py/code/tbpresent.py
==============================================================================
--- py/branch/event/py/code/tbpresent.py	(original)
+++ py/branch/event/py/code/tbpresent.py	Fri Aug  1 13:46:29 2008
@@ -10,10 +10,13 @@
     flow_marker = ">"    
     fail_marker = "E"
     
-    def __init__(self, showlocals=False, style="long"):
+    def __init__(self, out=None, showlocals=False, style="long"):
         self.showlocals = showlocals
         self.style = style
-        self.out = py.io.TerminalWriter()
+        if out is None:
+            self.out = py.io.TerminalWriter()
+        else:
+            self.out = out
 
     def repr_source(self, source, marker_location=-1):
         """ This one represents piece of source with possible

Modified: py/branch/event/py/test2/rep/base.py
==============================================================================
--- py/branch/event/py/test2/rep/base.py	(original)
+++ py/branch/event/py/test2/rep/base.py	Fri Aug  1 13:46:29 2008
@@ -28,8 +28,9 @@
 
     def rep_CollectionFinish(self, ev):
         outcome = ev.runinfo.outcome
-        if outcome == "failed":
-            l = self._outcome2rep.setdefault("failed_collection", [])
+        if outcome in ("failed", "skipped"):
+            key = outcome + "_collection"
+            l = self._outcome2rep.setdefault(key, [])
             l.append(ev)
 
     def getreports(self, outcome=None, category=None):
@@ -38,7 +39,10 @@
             the category.
         """
         if outcome is not None:
-            if outcome not in repevent.validoutcomes:
+            check = outcome 
+            if outcome.endswith("_collection"):
+               check = outcome[:outcome.rfind("_")]
+            if check not in repevent.validoutcomes:
                 raise ValueError("not a valid outcome %r" %(outcome))
             l = self._outcome2rep.setdefault(outcome, [])
             return l[:]
@@ -48,6 +52,10 @@
                 l += self.getreports("failed_crashed")
                 l += self.getreports("failed_setup")
                 l += self.getreports("failed_collection")
-                return l 
-            return self.getreports(category)
+            elif category == "skipped":
+                l = self.getreports("skipped")
+                l += self.getreports("skipped_collection")
+            else:
+                l = self.getreports(category)
+            return l 
 

Modified: py/branch/event/py/test2/rep/terminal.py
==============================================================================
--- py/branch/event/py/test2/rep/terminal.py	(original)
+++ py/branch/event/py/test2/rep/terminal.py	Fri Aug  1 13:46:29 2008
@@ -38,7 +38,8 @@
         self.out.line("")
         for ev in self.getreports(category="failed"):
             #self.out.sep("_", "entrypoint: %s" %(ev.repr_path[1],))
-            try: self.out.line(ev.repr_run)
+            try: 
+                self.out.line(ev.repr_run)
             except AttributeError:
                 self.out.line(ev.runinfo.repr_run())
         #self.out.sep("=")

Modified: py/branch/event/py/test2/rep/testing/test_basereporter.py
==============================================================================
--- py/branch/event/py/test2/rep/testing/test_basereporter.py	(original)
+++ py/branch/event/py/test2/rep/testing/test_basereporter.py	Fri Aug  1 13:46:29 2008
@@ -97,3 +97,21 @@
         assert l == [ev]
         l = rep.getreports("failed_collection")
         assert l == [ev]
+
+    def test_skip_testitems_and_collections(self):
+        rep = BaseReporter()
+        runinfo = RunInfo(None, "skipped", None, None)
+        ev1 = repevent.CollectionFinish(None, runinfo)
+        rep.processevent(ev1)
+        ev2 = repevent.ItemTestReport(None, "skipped", None, None)
+        rep.processevent(ev2)
+        l = rep.getreports(category="skipped")
+        assert l == [ev2, ev1] 
+        l = rep.getreports("skipped_collection")
+        assert l == [ev1]
+
+    def test_skip_reasons(self):
+        
+        
+        
+

Modified: py/branch/event/py/test2/testing/acceptance_test.py
==============================================================================
--- py/branch/event/py/test2/testing/acceptance_test.py	(original)
+++ py/branch/event/py/test2/testing/acceptance_test.py	Fri Aug  1 13:46:29 2008
@@ -4,7 +4,26 @@
 def setup_module(mod):
     mod.modtmpdir = py.test2.ensuretemp(mod.__name__)
 
+class Result:
+    def __init__(self, ret, outlines, errlines):
+        self.ret = ret
+        self.outlines = outlines
+        self.errlines = errlines
+
 class TestPyTest:
+    def runpytest(self, *args):
+        pytestcmd = py.path.local(py.__file__).dirpath("bin", "py.test2")
+        cmdargs = [py.std.sys.executable, pytestcmd] + list(args)
+        cmdargs = map(str, cmdargs)
+        p1 = py.path.local("stdout")
+        p2 = py.path.local("stderr")
+        print "running", cmdargs, "curdir=", py.path.local()
+        popen = py.std.subprocess.Popen(cmdargs, 
+            stdout=p1.open("w"), stderr=p2.open("w"))
+        ret = popen.wait()
+        out, err = p1.readlines(cr=0), p2.readlines(cr=0)
+        return Result(ret, out, err)
+
     def setup_method(self, method):
         name = self.__class__.__name__ + "_" + method.__name__
         self.old = modtmpdir.mkdir(name).chdir()
@@ -47,20 +66,38 @@
         ])
         assert result.ret == 1
 
-    def runpytest(self, *args):
-        pytestcmd = py.path.local(py.__file__).dirpath("bin", "py.test2")
-        cmdargs = [py.std.sys.executable, pytestcmd] + list(args)
-        cmdargs = map(str, cmdargs)
-        p1 = py.path.local("stdout")
-        p2 = py.path.local("stderr")
-        popen = py.std.subprocess.Popen(cmdargs, 
-            stdout=p1.open("w"), stderr=p2.open("w"))
-        ret = popen.wait()
-        out, err = p1.readlines(cr=0), p2.readlines(cr=0)
-        return Result(ret, out, err)
+    def makepyfile(self, **kwargs):
+        assert len(kwargs) == 1
+        name, value = kwargs.popitem()
+        p = py.path.local(name).new(ext=".py")
+        p.write(py.code.Source(value))
+        return p 
+
+    def test_skipped_reasons(self):
+        p1 = self.makepyfile(test_one="""
+            from conftest import doskip
+            def setup_function(func):
+                doskip()
+            def test_func():
+                pass
+            class TestClass:
+                def test_method(self):
+                    doskip()
+        """)
+        p2 = self.makepyfile(test_two="""
+            from conftest import doskip
+            doskip()
+        """)
+        p3 = self.makepyfile(conftest="""
+            import py
+            def doskip():
+                py.test.skip('test')
+        """)
+        result = self.runpytest()
+        extra = assert_lines_contain_lines(result.outlines, [
+            "*test_one.py ss",
+            "*test_two.py - Skipped -",
+            "___* reasons for skipped tests *___",
+            "%s:3: 3 Skipped, reason: test" %(p3,)
+        ])
 
-class Result:
-    def __init__(self, ret, outlines, errlines):
-        self.ret = ret
-        self.outlines = outlines
-        self.errlines = errlines

Modified: py/branch/event/py/test2/testing/suptest.py
==============================================================================
--- py/branch/event/py/test2/testing/suptest.py	(original)
+++ py/branch/event/py/test2/testing/suptest.py	Fri Aug  1 13:46:29 2008
@@ -13,6 +13,7 @@
 """
 import py
 from py.__.test2 import repevent
+from fnmatch import fnmatch
 
 def eventappender(config):
     l = []
@@ -141,11 +142,13 @@
     for line in lines2:
         while lines1:
             nextline = lines1.pop(0)
-            print "comparing", repr(line)
-            print "and     :", repr(nextline)
             if line == nextline:
-                print "match:", repr(line)
+                print "exact match:", repr(line)
                 break 
+            elif fnmatch(nextline, line):
+                print "fnmatch:", repr(line), repr(nextline)
+            else:
+                print "nomatch:", repr(line), repr(nextline)
             extralines.append(nextline)
         else:
             if line != nextline:



More information about the pytest-commit mailing list