Skip to content

Commit ccf9877

Browse files
authored
Merge pull request #2232 from vidartf/patch-1
Do not asssume `Item.obj` in 'skipping' plugin
2 parents a4d2a57 + 832c89d commit ccf9877

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,5 +142,6 @@ Trevor Bekolay
142142
Tyler Goodlet
143143
Vasily Kuznetsov
144144
Victor Uriarte
145+
Vidar T. Fauske
145146
Wouter van Ackooy
146147
Xuecong Liao

CHANGELOG.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
* Replace ``raise StopIteration`` usages in the code by simple ``returns`` to finish generators, in accordance to `PEP-479`_ (`#2160`_).
77
Thanks `@tgoodlet`_ for the report and `@nicoddemus`_ for the PR.
88

9-
*
9+
* Skipping plugin now also works with test items generated by custom collectors (`#2231`_).
10+
Thanks to `@vidartf`_.
1011

1112
* Conditionless ``xfail`` markers no longer rely on the underlying test item
1213
being an instance of ``PyobjMixin``, and can therefore apply to tests not
@@ -19,6 +20,10 @@
1920

2021
.. _PEP-479: https://www.python.org/dev/peps/pep-0479/
2122

23+
.. _#2231: https://github.com/pytest-dev/pytest/issues/2231
24+
25+
.. _@vidartf: https://github.com/vidartf
26+
2227

2328
3.0.6 (2017-01-22)
2429
==================

_pytest/skipping.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ def istrue(self):
112112

113113
def _getglobals(self):
114114
d = {'os': os, 'sys': sys, 'config': self.item.config}
115-
d.update(self.item.obj.__globals__)
115+
if hasattr(self.item, 'obj'):
116+
d.update(self.item.obj.__globals__)
116117
return d
117118

118119
def _istrue(self):

testing/test_skipping.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -969,3 +969,26 @@ def test_func():
969969
result.stdout.fnmatch_lines(
970970
"*Using pytest.skip outside of a test is not allowed*"
971971
)
972+
973+
974+
def test_mark_xfail_item(testdir):
975+
# Ensure pytest.mark.xfail works with non-Python Item
976+
testdir.makeconftest("""
977+
import pytest
978+
979+
class MyItem(pytest.Item):
980+
nodeid = 'foo'
981+
def setup(self):
982+
marker = pytest.mark.xfail(True, reason="Expected failure")
983+
self.add_marker(marker)
984+
def runtest(self):
985+
assert False
986+
987+
def pytest_collect_file(path, parent):
988+
return MyItem("foo", parent)
989+
""")
990+
result = testdir.inline_run()
991+
passed, skipped, failed = result.listoutcomes()
992+
assert not failed
993+
xfailed = [r for r in skipped if hasattr(r, 'wasxfail')]
994+
assert xfailed

0 commit comments

Comments
 (0)