[Pytest-commit] commit/pytest: 3 new changesets

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Tue Apr 16 09:14:59 CEST 2013


3 new commits in pytest:

https://bitbucket.org/hpk42/pytest/commits/5d9007722ea1/
Changeset:   5d9007722ea1
User:        hpk42
Date:        2013-04-16 09:04:05
Summary:     slightly improve -k help string
cosmetic change to test_nose.py
Affected #:  2 files

diff -r 82139da07b58da52fc124be4218c8957b71f3ac1 -r 5d9007722ea163f43d4115f76a72cfd527111cbd _pytest/mark.py
--- a/_pytest/mark.py
+++ b/_pytest/mark.py
@@ -7,8 +7,8 @@
 def pytest_addoption(parser):
     group = parser.getgroup("general")
     group._addoption('-k',
-        action="store", dest="keyword", default='', metavar="KEYWORDEXPR",
-        help="only run tests which match the given expression. "
+        action="store", dest="keyword", default='', metavar="EXPRESSION",
+        help="only run tests which match the given substring expression. "
              "An expression is a python evaluatable expression "
              "where all names are substring-matched against test names "
              "and keywords.  Example: -k 'test_method or test_other' "

diff -r 82139da07b58da52fc124be4218c8957b71f3ac1 -r 5d9007722ea163f43d4115f76a72cfd527111cbd testing/test_nose.py
--- a/testing/test_nose.py
+++ b/testing/test_nose.py
@@ -304,8 +304,9 @@
     result = testdir.runpytest()
     result.stdout.fnmatch_lines("*1 passed*")
 
+ at pytest.mark.skipif("sys.version_info < (2,6)")
 def test_setup_teardown_linking_issue265(testdir):
-    # we accidnetially didnt integrate nose setupstate with normal setupstate
+    # we accidentally didnt integrate nose setupstate with normal setupstate
     # this test ensures that won't happen again
     testdir.makepyfile('''
         import pytest
@@ -314,7 +315,8 @@
             def test_nothing(self):
                 """Tests the API of the implementation (for generic and specialized)."""
 
-        @pytest.mark.skipif("True", reason="Skip tests to check if teardown is skipped as well.")
+        @pytest.mark.skipif("True", reason=
+                    "Skip tests to check if teardown is skipped as well.")
         class TestSkipTeardown(TestGeneric):
 
             def setup(self):


https://bitbucket.org/hpk42/pytest/commits/af95db883582/
Changeset:   af95db883582
User:        hpk42
Date:        2013-04-16 09:13:58
Summary:     merge
Affected #:  4 files

diff -r 5d9007722ea163f43d4115f76a72cfd527111cbd -r af95db883582c12caf5e6b65b7b2fed022fe6e70 _pytest/capture.py
--- a/_pytest/capture.py
+++ b/_pytest/capture.py
@@ -173,8 +173,7 @@
         if funcarg_outerr is not None:
             outerr = (outerr[0] + funcarg_outerr[0],
                       outerr[1] + funcarg_outerr[1])
-        if not rep.passed:
-            addouterr(rep, outerr)
+        addouterr(rep, outerr)
         if not rep.passed or rep.when == "teardown":
             outerr = ('', '')
         item.outerr = outerr

diff -r 5d9007722ea163f43d4115f76a72cfd527111cbd -r af95db883582c12caf5e6b65b7b2fed022fe6e70 _pytest/junitxml.py
--- a/_pytest/junitxml.py
+++ b/_pytest/junitxml.py
@@ -107,11 +107,20 @@
             time=getattr(report, 'duration', 0)
         ))
 
+    def _write_captured_output(self, report):
+        sec = dict(report.sections)
+        for name in ('out', 'err'):
+            content = sec.get("Captured std%s" % name)
+            if content:
+                tag = getattr(Junit, 'system-'+name)
+                self.append(tag(bin_xml_escape(content)))
+
     def append(self, obj):
         self.tests[-1].append(obj)
 
     def append_pass(self, report):
         self.passed += 1
+        self._write_captured_output(report)
 
     def append_failure(self, report):
         #msg = str(report.longrepr.reprtraceback.extraline)
@@ -120,16 +129,11 @@
                 Junit.skipped(message="xfail-marked test passes unexpectedly"))
             self.skipped += 1
         else:
-            sec = dict(report.sections)
             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:
-                    tag = getattr(Junit, 'system-'+name)
-                    self.append(tag(bin_xml_escape(content)))
             self.failed += 1
+        self._write_captured_output(report)
 
     def append_collect_failure(self, report):
         #msg = str(report.longrepr.reprtraceback.extraline)
@@ -162,6 +166,7 @@
                               message=skipreason
                 ))
         self.skipped += 1
+        self._write_captured_output(report)
 
     def pytest_runtest_logreport(self, report):
         if report.passed:

diff -r 5d9007722ea163f43d4115f76a72cfd527111cbd -r af95db883582c12caf5e6b65b7b2fed022fe6e70 _pytest/pdb.py
--- a/_pytest/pdb.py
+++ b/_pytest/pdb.py
@@ -70,16 +70,21 @@
         tw.sep(">", "traceback")
         rep.toterminal(tw)
         tw.sep(">", "entering PDB")
-        # A doctest.UnexpectedException is not useful for post_mortem.
-        # Use the underlying exception instead:
-        if isinstance(call.excinfo.value, py.std.doctest.UnexpectedException):
-            tb = call.excinfo.value.exc_info[2]
-        else:
-            tb = call.excinfo._excinfo[2]
+
+        tb = self._postmortem_traceback(call.excinfo)
         post_mortem(tb)
         rep._pdbshown = True
         return rep
 
+    @staticmethod
+    def _postmortem_traceback(excinfo):
+        # A doctest.UnexpectedException is not useful for post_mortem.
+        # Use the underlying exception instead:
+        if isinstance(excinfo.value, py.std.doctest.UnexpectedException):
+            return excinfo.value.exc_info[2]
+        else:
+            return excinfo._excinfo[2]
+
 def post_mortem(t):
     pdb = py.std.pdb
     class Pdb(pdb.Pdb):

diff -r 5d9007722ea163f43d4115f76a72cfd527111cbd -r af95db883582c12caf5e6b65b7b2fed022fe6e70 testing/test_junitxml.py
--- a/testing/test_junitxml.py
+++ b/testing/test_junitxml.py
@@ -282,13 +282,35 @@
         if not sys.platform.startswith("java"):
             assert "hx" in fnode.toxml()
 
+    def test_pass_captures_stdout(self, testdir):
+        testdir.makepyfile("""
+            def test_pass():
+                print('hello-stdout')
+        """)
+        result, dom = runandparse(testdir)
+        node = dom.getElementsByTagName("testsuite")[0]
+        pnode = node.getElementsByTagName("testcase")[0]
+        systemout = pnode.getElementsByTagName("system-out")[0]
+        assert "hello-stdout" in systemout.toxml()
+
+    def test_pass_captures_stderr(self, testdir):
+        testdir.makepyfile("""
+            import sys
+            def test_pass():
+                sys.stderr.write('hello-stderr')
+        """)
+        result, dom = runandparse(testdir)
+        node = dom.getElementsByTagName("testsuite")[0]
+        pnode = node.getElementsByTagName("testcase")[0]
+        systemout = pnode.getElementsByTagName("system-err")[0]
+        assert "hello-stderr" in systemout.toxml()
+
 def test_mangle_testnames():
     from _pytest.junitxml import mangle_testnames
     names = ["a/pything.py", "Class", "()", "method"]
     newnames = mangle_testnames(names)
     assert newnames == ["a.pything", "Class", "method"]
 
-
 def test_dont_configure_on_slaves(tmpdir):
     gotten = []
     class FakeConfig:


https://bitbucket.org/hpk42/pytest/commits/e648b0ab9f00/
Changeset:   e648b0ab9f00
User:        hpk42
Date:        2013-04-16 09:14:47
Summary:     add to changelog: put captured stdout/stderr into junitxml output even
for passing tests (thanks Adam Goucher)
Affected #:  1 file

diff -r af95db883582c12caf5e6b65b7b2fed022fe6e70 -r e648b0ab9f006799cce2e4ed229eec9d3a26a9c0 CHANGELOG
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,9 @@
 Changes between 2.3.4 and 2.3.5dev
 -----------------------------------
 
+- put captured stdout/stderr into junitxml output even for passing tests
+  (thanks Adam Goucher)
+
 - Issue 265 - integrate nose setup/teardown with setupstate
   so it doesnt try to teardown if it did not setup

Repository URL: https://bitbucket.org/hpk42/pytest/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.


More information about the pytest-commit mailing list