Merge pull request #2232 from vidartf/patch-1

Do not asssume `Item.obj` in 'skipping' plugin
This commit is contained in:
Bruno Oliveira 2017-02-03 21:39:42 -02:00 committed by GitHub
commit ccf9877447
4 changed files with 32 additions and 2 deletions

View File

@ -142,5 +142,6 @@ Trevor Bekolay
Tyler Goodlet
Vasily Kuznetsov
Victor Uriarte
Vidar T. Fauske
Wouter van Ackooy
Xuecong Liao

View File

@ -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
@ -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)
==================

View File

@ -112,7 +112,8 @@ class MarkEvaluator:
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):

View File

@ -969,3 +969,26 @@ def test_module_level_skip_error(testdir):
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