[Pytest-commit] commit/pytest: flub: Let xfail work on non-python Items

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Wed Sep 24 13:52:03 CEST 2014


1 new commit in pytest:

https://bitbucket.org/hpk42/pytest/commits/79d43914cf2f/
Changeset:   79d43914cf2f
User:        flub
Date:        2014-09-23 22:55:26+00:00
Summary:     Let xfail work on non-python Items

For some reason xfail was only implemented on non-python Item
instances.  This removes this guard which means plugins creating new
items can raise pytest.xfail.Exception and it will work as expected.
Affected #:  2 files

diff -r fcfcf15459f0e4ab43e8784befcd83ded913c8b2 -r 79d43914cf2f99b25a3b65f90a07a036b33e165f _pytest/skipping.py
--- a/_pytest/skipping.py
+++ b/_pytest/skipping.py
@@ -58,6 +58,7 @@
     @property
     def holder(self):
         return self.item.keywords.get(self.name, None)
+
     def __bool__(self):
         return bool(self.holder)
     __nonzero__ = __bool__
@@ -136,8 +137,6 @@
 
 @pytest.mark.tryfirst
 def pytest_runtest_setup(item):
-    if not isinstance(item, pytest.Function):
-        return
     evalskip = MarkEvaluator(item, 'skipif')
     if evalskip.istrue():
         pytest.skip(evalskip.getexplanation())
@@ -155,8 +154,6 @@
                 pytest.xfail("[NOTRUN] " + evalxfail.getexplanation())
 
 def pytest_runtest_makereport(__multicall__, item, call):
-    if not isinstance(item, pytest.Function):
-        return
     # unitttest special case, see setting of _unexpectedsuccess
     if hasattr(item, '_unexpectedsuccess'):
         rep = __multicall__.execute()

diff -r fcfcf15459f0e4ab43e8784befcd83ded913c8b2 -r 79d43914cf2f99b25a3b65f90a07a036b33e165f testing/test_skipping.py
--- a/testing/test_skipping.py
+++ b/testing/test_skipping.py
@@ -678,3 +678,23 @@
             *True123*
             *1 xfail*
         """)
+
+
+def test_xfail_item(testdir):
+    # Ensure pytest.xfail works with non-Python Item
+    testdir.makeconftest("""
+        import pytest
+
+        class MyItem(pytest.Item):
+            nodeid = 'foo'
+            def runtest(self):
+                pytest.xfail("Expected Failure")
+
+        def pytest_collect_file(path, parent):
+            return MyItem("foo", parent)
+    """)
+    result = testdir.inline_run()
+    passed, skipped, failed = result.listoutcomes()
+    assert not failed
+    xfailed = [r for r in skipped if hasattr(r, 'wasxfail')]
+    assert xfailed

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