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.
This commit is contained in:
		
							parent
							
								
									68105b3ae4
								
							
						
					
					
						commit
						62b8712ca9
					
				|  | @ -58,6 +58,7 @@ class MarkEvaluator: | |||
|     @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 @@ class MarkEvaluator: | |||
| 
 | ||||
| @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 @@ def check_xfail_no_run(item): | |||
|                 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() | ||||
|  |  | |||
|  | @ -678,3 +678,23 @@ class TestBooleanCondition: | |||
|             *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 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue