Skip to content

Commit

Permalink
Merge pull request pytest-dev#2232 from vidartf/patch-1
Browse files Browse the repository at this point in the history
Do not asssume `Item.obj` in 'skipping' plugin
  • Loading branch information
nicoddemus authored Feb 3, 2017
2 parents a4d2a57 + 832c89d commit ccf9877
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -142,5 +142,6 @@ Trevor Bekolay
Tyler Goodlet
Vasily Kuznetsov
Victor Uriarte
Vidar T. Fauske
Wouter van Ackooy
Xuecong Liao
7 changes: 6 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
* Replace ``raise StopIteration`` usages in the code by simple ``returns`` to finish generators, in accordance to `PEP-479`_ (`#2160`_).
Thanks `@tgoodlet`_ for the report and `@nicoddemus`_ for the PR.

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

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

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

.. _#2231: https://github.com/pytest-dev/pytest/issues/2231

.. _@vidartf: https://github.com/vidartf


3.0.6 (2017-01-22)
==================
Expand Down
3 changes: 2 additions & 1 deletion _pytest/skipping.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ def istrue(self):

def _getglobals(self):
d = {'os': os, 'sys': sys, 'config': self.item.config}
d.update(self.item.obj.__globals__)
if hasattr(self.item, 'obj'):
d.update(self.item.obj.__globals__)
return d

def _istrue(self):
Expand Down
23 changes: 23 additions & 0 deletions testing/test_skipping.py
Original file line number Diff line number Diff line change
Expand Up @@ -969,3 +969,26 @@ def test_func():
result.stdout.fnmatch_lines(
"*Using pytest.skip outside of a test is not allowed*"
)


def test_mark_xfail_item(testdir):
# Ensure pytest.mark.xfail works with non-Python Item
testdir.makeconftest("""
import pytest
class MyItem(pytest.Item):
nodeid = 'foo'
def setup(self):
marker = pytest.mark.xfail(True, reason="Expected failure")
self.add_marker(marker)
def runtest(self):
assert False
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

0 comments on commit ccf9877

Please sign in to comment.