Commits

Ronny Pfannschmidt committed d4c3d91

stuff

Comments (0)

Files changed (5)

+# HG changeset patch
+# Parent dcb6bcf7773d08365d289092dabf94c4cd6d6049
+
+diff --git a/_pytest/junitxml.py b/_pytest/junitxml.py
+--- a/_pytest/junitxml.py
++++ b/_pytest/junitxml.py
+@@ -25,6 +25,10 @@ except NameError:
+     long = int
+ 
+ 
++class Junit(py.xml.Namespace):
++    pass
++
++
+ # We need to get the subset of the invalid unicode ranges according to
+ # XML 1.0 which are valid in this python build.  Hence we calculate
+ # this dynamically instead of hardcoding it.  The spec range of valid
+@@ -40,6 +44,14 @@ illegal_xml_re = re.compile(unicode('[%s
+ del _illegal_unichrs
+ del _illegal_ranges
+ 
++def bin_xml_escape(arg):
++    def repl(matchobj):
++        i = ord(matchobj.group())
++        if i <= 0xFF:
++            return unicode('#x%02X') % i
++        else:
++            return unicode('#x%04X') % i
++    return illegal_xml_re.sub(repl, py.xml.escape(arg))
+ 
+ def pytest_addoption(parser):
+     group = parser.getgroup("terminal reporting")
+@@ -68,7 +80,7 @@ class LogXML(object):
+         logfile = os.path.expanduser(os.path.expandvars(logfile))
+         self.logfile = os.path.normpath(logfile)
+         self.prefix = prefix
+-        self.test_logs = []
++        self.tests = []
+         self.passed = self.skipped = 0
+         self.failed = self.errors = 0
+ 
+@@ -82,89 +94,67 @@ class LogXML(object):
+         if self.prefix:
+             classnames.insert(0, self.prefix)
+         d['classname'] = ".".join(classnames)
+-        d['name'] = py.xml.escape(names[-1])
+-        attrs = ['%s="%s"' % item for item in sorted(d.items())]
+-        self.test_logs.append("\n<testcase %s>" % " ".join(attrs))
++        d['name'] = names[-1]
++        self.tests.append(Junit.testcase(**d))
+ 
+-    def _closetestcase(self):
+-        self.test_logs.append("</testcase>")
+-
+-    def appendlog(self, fmt, *args):
+-        def repl(matchobj):
+-            i = ord(matchobj.group())
+-            if i <= 0xFF:
+-                return unicode('#x%02X') % i
+-            else:
+-                return unicode('#x%04X') % i
+-        args = tuple([illegal_xml_re.sub(repl, py.xml.escape(arg))
+-                      for arg in args])
+-        self.test_logs.append(fmt % args)
++    def append(self, obj):
++        self.tests[-1].append(obj)
+ 
+     def append_pass(self, report):
+         self.passed += 1
+-        self._opentestcase(report)
+-        self._closetestcase()
+ 
+     def append_failure(self, report):
+-        self._opentestcase(report)
+         #msg = str(report.longrepr.reprtraceback.extraline)
+         if "xfail" in report.keywords:
+-            self.appendlog(
+-                '<skipped message="xfail-marked test passes unexpectedly"/>')
++            self.append(
++                Junit.skipped(message="xfail-marked test passes unexpectedly"))
+             self.skipped += 1
+         else:
+             sec = dict(report.sections)
+-            self.appendlog('<failure message="test failure">%s</failure>',
+-                report.longrepr)
++            fail = Junit.failure(message="test failure")
++            fail.append(str(report.longrepr))
++            self.append(fail)
+             for name in ('out', 'err'):
+                 content = sec.get("Captured std%s" % name)
+                 if content:
+-                    self.appendlog(
+-                        "<system-%s>%%s</system-%s>" % (name, name), content)
++                    tag = getattr(Junit, 'system-'+name)
++                    self.append(tag(bin_xml_escape(content)))
+             self.failed += 1
+-        self._closetestcase()
+ 
+     def append_collect_failure(self, report):
+-        self._opentestcase(report)
+         #msg = str(report.longrepr.reprtraceback.extraline)
+-        self.appendlog('<failure message="collection failure">%s</failure>',
+-            report.longrepr)
+-        self._closetestcase()
++        self.append(Junit.failure(str(report.longrepr),
++                                  message="collection failure"))
+         self.errors += 1
+ 
+     def append_collect_skipped(self, report):
+-        self._opentestcase(report)
+         #msg = str(report.longrepr.reprtraceback.extraline)
+-        self.appendlog('<skipped message="collection skipped">%s</skipped>',
+-            report.longrepr)
+-        self._closetestcase()
++        self.append(Junit.skipped(str(report.longrepr),
++                                  message="collection skipped"))
+         self.skipped += 1
+ 
+     def append_error(self, report):
+-        self._opentestcase(report)
+-        self.appendlog('<error message="test setup failure">%s</error>',
+-            report.longrepr)
+-        self._closetestcase()
++        self.append(Junit.error(str(report.longrepr),
++                                message="test setup failure"))
+         self.errors += 1
+ 
+     def append_skipped(self, report):
+-        self._opentestcase(report)
+         if "xfail" in report.keywords:
+-            self.appendlog(
+-                '<skipped message="expected test failure">%s</skipped>',
+-                report.keywords['xfail'])
++            self.append(Junit.skipped(str(report.keywords['xfail']),
++                                      message="expected test failure"))
+         else:
+             filename, lineno, skipreason = report.longrepr
+             if skipreason.startswith("Skipped: "):
+                 skipreason = skipreason[9:]
+-            self.appendlog('<skipped type="pytest.skip" '
+-                           'message="%s">%s</skipped>',
+-                skipreason, "%s:%s: %s" % report.longrepr,
+-                )
+-        self._closetestcase()
++            self.append(
++                Junit.skipped("%s:%s: %s" % report.longrepr,
++                              type="pytest.skip",
++                              message=skipreason
++                ))
+         self.skipped += 1
+ 
+     def pytest_runtest_logreport(self, report):
++        self._opentestcase(report)
+         if report.passed:
+             if report.when == "call": # ignore setup/teardown
+                 self.append_pass(report)
+@@ -178,6 +168,7 @@ class LogXML(object):
+ 
+     def pytest_collectreport(self, report):
+         if not report.passed:
++            self._opentestcase(report)
+             if report.failed:
+                 self.append_collect_failure(report)
+             else:
+@@ -186,10 +177,11 @@ class LogXML(object):
+     def pytest_internalerror(self, excrepr):
+         self.errors += 1
+         data = py.xml.escape(excrepr)
+-        self.test_logs.append(
+-            '\n<testcase classname="pytest" name="internal">'
+-            '    <error message="internal error">'
+-            '%s</error></testcase>' % data)
++        self.tests.append(
++            Junit.testcase(
++                    Junit.error(data, message="internal error"),
++                    classname="pytest",
++                    name="internal"))
+ 
+     def pytest_sessionstart(self, session):
+         self.suite_start_time = time.time()
+@@ -203,17 +195,17 @@ class LogXML(object):
+         suite_stop_time = time.time()
+         suite_time_delta = suite_stop_time - self.suite_start_time
+         numtests = self.passed + self.failed
++
+         logfile.write('<?xml version="1.0" encoding="utf-8"?>')
+-        logfile.write('<testsuite ')
+-        logfile.write('name="" ')
+-        logfile.write('errors="%i" ' % self.errors)
+-        logfile.write('failures="%i" ' % self.failed)
+-        logfile.write('skips="%i" ' % self.skipped)
+-        logfile.write('tests="%i" ' % numtests)
+-        logfile.write('time="%.3f"' % suite_time_delta)
+-        logfile.write(' >')
+-        logfile.writelines(self.test_logs)
+-        logfile.write('</testsuite>')
++        logfile.write(Junit.testsuite(
++            self.tests,
++            name="",
++            errors=self.errors,
++            failures=self.failed,
++            skips=self.skipped,
++            tests=numtests,
++            time="%.3f" % suite_time_delta,
++        ).unicode(indent=0))
+         logfile.close()
+ 
+     def pytest_terminal_summary(self, terminalreporter):
+# HG changeset patch
+# Parent 3d9f1a7f04da2bed0bcda6186058b40428f2cdbe
+diff --git a/_pytest/main.py b/_pytest/main.py
+--- a/_pytest/main.py
++++ b/_pytest/main.py
+@@ -227,12 +227,10 @@ class Node(object):
+         """ return list of all parent collectors up to self,
+             starting from root of collection tree. """
+         l = [self]
+-        while 1:
+-            x = l[0]
+-            if x.parent is not None: # and x.parent.parent is not None:
+-                l.insert(0, x.parent)
+-            else:
+-                return l
++        while l[-1].parent is not None:
++            l.append(l[-1].parent)
++        l.reverse()
++        return l
+ 
+     def listnames(self):
+         return [x.name for x in self.listchain()]

regendoc-pytesthighlight

+# HG changeset patch
+# Parent 5c030fad0636dd42ad3ab7bc4968c57d3b0049e1
+use codeblocks with pytest syntax to get reasonable coloring
+
+diff --git a/doc/assert.txt b/doc/assert.txt
+--- a/doc/assert.txt
++++ b/doc/assert.txt
+@@ -19,7 +19,9 @@ following::
+         assert f() == 4
+ 
+ to assert that your function returns a certain value. If this assertion fails
+-you will see the return value of the function call::
++you will see the return value of the function call:
++
++.. code-block:: pytest
+ 
+     $ py.test test_assert1.py
+     =========================== test session starts ============================
+@@ -101,7 +103,9 @@ when it encounters comparisons.  For exa
+         set2 = set("8035")
+         assert set1 == set2
+ 
+-if you run this module::
++if you run this module:
++
++.. code-block:: pytest
+ 
+     $ py.test test_assert2.py
+     =========================== test session starts ============================
+@@ -165,7 +169,9 @@ now, given this test module::
+        assert f1 == f2
+ 
+ you can run the test module and get the custom output defined in 
+-the conftest file::
++the conftest file:
++
++.. code-block:: pytest
+ 
+    $ py.test -q test_foocompare.py
+    collecting ... collected 1 items
+diff --git a/doc/builtin.txt b/doc/builtin.txt
+--- a/doc/builtin.txt
++++ b/doc/builtin.txt
+@@ -24,7 +24,9 @@ Builtin function arguments
+ -----------------------------------------------------
+ 
+ You can ask for available builtin or project-custom
+-:ref:`function arguments <funcargs>` by typing::
++:ref:`function arguments <funcargs>` by typing:
++
++.. code-block:: pytest
+ 
+     $ py.test --funcargs
+     =========================== test session starts ============================
+diff --git a/doc/capture.txt b/doc/capture.txt
+--- a/doc/capture.txt
++++ b/doc/capture.txt
+@@ -60,7 +60,9 @@ is that you can use print statements for
+         assert False
+ 
+ and running this module will show you precisely the output
+-of the failing function and hide the other one::
++of the failing function and hide the other one:
++
++.. code-block:: pytest
+ 
+     $ py.test
+     =========================== test session starts ============================
+diff --git a/doc/doctest.txt b/doc/doctest.txt
+--- a/doc/doctest.txt
++++ b/doc/doctest.txt
+@@ -40,7 +40,9 @@ and another like this::
+         """
+         return 42
+ 
+-then you can just invoke ``py.test`` without command line options::
++then you can just invoke ``py.test`` without command line options:
++
++.. code-block:: pytest
+ 
+     $ py.test
+     =========================== test session starts ============================
+diff --git a/doc/funcargs.txt b/doc/funcargs.txt
+--- a/doc/funcargs.txt
++++ b/doc/funcargs.txt
+@@ -58,7 +58,9 @@ This test function needs an injected obj
+ py.test will discover and call the factory named
+ ``pytest_funcarg__myfuncarg`` within the same module in this case.
+ 
+-Running the test looks like this::
++Running the test looks like this:
++
++.. code-block:: pytest
+ 
+     $ py.test test_simplefactory.py
+     =========================== test session starts ============================
+@@ -163,7 +165,9 @@ hook to generate several calls to the sa
+     def test_func(numiter):
+         assert numiter < 9
+ 
+-Running this will generate ten invocations of ``test_func`` passing in each of the items in the list of ``range(10)``::
++Running this will generate ten invocations of ``test_func`` passing in each of the items in the list of ``range(10)``:
++
++.. code-block:: pytest
+ 
+     $ py.test test_example.py
+     =========================== test session starts ============================
+@@ -186,7 +190,9 @@ Running this will generate ten invocatio
+ 
+ Obviously, only when ``numiter`` has the value of ``9`` does the test fail.  Note that the ``pytest_generate_tests(metafunc)`` hook is called during
+ the test collection phase which is separate from the actual test running.
+-Let's just look at what is collected::
++Let's just look at what is collected:
++
++.. code-bloc:: pytest
+ 
+     $ py.test --collectonly test_example.py
+     =========================== test session starts ============================
+@@ -206,7 +212,9 @@ Let's just look at what is collected::
+     
+     =============================  in 0.01 seconds =============================
+ 
+-If you want to select only the run with the value ``7`` you could do::
++If you want to select only the run with the value ``7`` you could do:
++
++.. code-block:: pytest
+ 
+     $ py.test -v -k 7 test_example.py  # or -k test_func[7]
+     =========================== test session starts ============================
+diff --git a/doc/getting-started.txt b/doc/getting-started.txt
+--- a/doc/getting-started.txt
++++ b/doc/getting-started.txt
+@@ -42,7 +42,9 @@ Let's create a first test file with a si
+     def test_answer():
+         assert func(3) == 5
+ 
+-That's it. You can execute the test function now::
++That's it. You can execute the test function now:
++
++.. code-block:: pytest
+ 
+     $ py.test
+     =========================== test session starts ============================
+@@ -90,7 +92,9 @@ use the ``raises`` helper::
+         with pytest.raises(SystemExit):
+             f()
+ 
+-Running it with, this time in "quiet" reporting mode::
++Running it with, this time in "quiet" reporting mode:
++
++.. code-block:: pytest
+ 
+     $ py.test -q test_sysexit.py
+     collecting ... collected 1 items
+@@ -118,7 +122,9 @@ containing two tests::
+ 
+ The two tests are found because of the standard :ref:`test discovery`.
+ There is no need to subclass anything.  We can simply
+-run the module by passing its filename::
++run the module by passing its filename:
++
++.. code-block:: pytest
+ 
+     $ py.test -q test_class.py
+     collecting ... collected 2 items
+@@ -155,7 +161,9 @@ arbitrary resources, for example a uniqu
+ 
+ We list the name ``tmpdir`` in the test function signature and
+ py.test will lookup and call a factory to create the resource
+-before performing the test function call.  Let's just run it::
++before performing the test function call.  Let's just run it:
++
++.. code-block:: pytest
+ 
+     $ py.test -q test_tmpdir.py
+     collecting ... collected 1 items
+diff --git a/doc/tmpdir.txt b/doc/tmpdir.txt
+--- a/doc/tmpdir.txt
++++ b/doc/tmpdir.txt
+@@ -24,7 +24,9 @@ and more.  Here is an example test usage
+         assert 0
+ 
+ Running this would result in a passed test except for the last
+-``assert 0`` line which we use to look at values::
++``assert 0`` line which we use to look at values:
++
++.. code-block:: pytest
+ 
+     $ py.test test_tmpdir.py
+     =========================== test session starts ============================
+diff --git a/doc/unittest.txt b/doc/unittest.txt
+--- a/doc/unittest.txt
++++ b/doc/unittest.txt
+@@ -20,7 +20,9 @@ of treating tests such as IO capturing::
+             x = 1
+             self.assertEquals(x, 3)
+        
+-Running it yields::
++Running it yields:
++
++.. code-block:: pytest
+ 
+     $ py.test test_unittest.py
+     =========================== test session starts ============================
+listchcain
+junitxml-pyxml
+regendoc-pytesthighlight #+docs
+unittest-skip-property #+unittest
 fnmatch-python-test-names #+test-names

unittest-skip-property

+# HG changeset patch
+# Parent ae08212f91afae3f2ee0320df72a51c3e188989a
+diff --git a/_pytest/unittest.py b/_pytest/unittest.py
+--- a/_pytest/unittest.py
++++ b/_pytest/unittest.py
+@@ -46,6 +46,10 @@ class TestCaseFunction(pytest.Function):
+     def setup(self):
+         self._testcase = self.parent.obj(self.name)
+         self._obj = getattr(self._testcase, self.name)
++        if hasattr(self._testcase, 'skip'):
++            pytest.skip(self._testcase.skip)
++        if hasattr(self._obj, 'skip'):
++            pytest.skip(self._obj.skip)
+         if hasattr(self._testcase, 'setup_method'):
+             self._testcase.setup_method(self._obj)
+