Merge pull request #3264 from jeffreyrack/3236-skipif-using-platform
#3236 Use platform module in pytest.mark
This commit is contained in:
commit
a968c0fa05
|
@ -1,6 +1,7 @@
|
||||||
import os
|
import os
|
||||||
import six
|
import six
|
||||||
import sys
|
import sys
|
||||||
|
import platform
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
from . import MarkDecorator, MarkInfo
|
from . import MarkDecorator, MarkInfo
|
||||||
|
@ -67,7 +68,7 @@ class MarkEvaluator(object):
|
||||||
pytrace=False)
|
pytrace=False)
|
||||||
|
|
||||||
def _getglobals(self):
|
def _getglobals(self):
|
||||||
d = {'os': os, 'sys': sys, 'config': self.item.config}
|
d = {'os': os, 'sys': sys, 'platform': platform, 'config': self.item.config}
|
||||||
if hasattr(self.item, 'obj'):
|
if hasattr(self.item, 'obj'):
|
||||||
d.update(self.item.obj.__globals__)
|
d.update(self.item.obj.__globals__)
|
||||||
return d
|
return d
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
The builtin module ``platform`` is now available for use in expressions in ``pytest.mark``.
|
|
@ -156,6 +156,21 @@ class TestXFail(object):
|
||||||
assert callreport.passed
|
assert callreport.passed
|
||||||
assert callreport.wasxfail == "this is an xfail"
|
assert callreport.wasxfail == "this is an xfail"
|
||||||
|
|
||||||
|
def test_xfail_using_platform(self, testdir):
|
||||||
|
"""
|
||||||
|
Verify that platform can be used with xfail statements.
|
||||||
|
"""
|
||||||
|
item = testdir.getitem("""
|
||||||
|
import pytest
|
||||||
|
@pytest.mark.xfail("platform.platform() == platform.platform()")
|
||||||
|
def test_func():
|
||||||
|
assert 0
|
||||||
|
""")
|
||||||
|
reports = runtestprotocol(item, log=False)
|
||||||
|
assert len(reports) == 3
|
||||||
|
callreport = reports[1]
|
||||||
|
assert callreport.wasxfail
|
||||||
|
|
||||||
def test_xfail_xpassed_strict(self, testdir):
|
def test_xfail_xpassed_strict(self, testdir):
|
||||||
item = testdir.getitem("""
|
item = testdir.getitem("""
|
||||||
import pytest
|
import pytest
|
||||||
|
@ -612,6 +627,16 @@ class TestSkipif(object):
|
||||||
])
|
])
|
||||||
assert result.ret == 0
|
assert result.ret == 0
|
||||||
|
|
||||||
|
def test_skipif_using_platform(self, testdir):
|
||||||
|
item = testdir.getitem("""
|
||||||
|
import pytest
|
||||||
|
@pytest.mark.skipif("platform.platform() == platform.platform()")
|
||||||
|
def test_func():
|
||||||
|
pass
|
||||||
|
""")
|
||||||
|
pytest.raises(pytest.skip.Exception, lambda:
|
||||||
|
pytest_runtest_setup(item))
|
||||||
|
|
||||||
@pytest.mark.parametrize('marker, msg1, msg2', [
|
@pytest.mark.parametrize('marker, msg1, msg2', [
|
||||||
('skipif', 'SKIP', 'skipped'),
|
('skipif', 'SKIP', 'skipped'),
|
||||||
('xfail', 'XPASS', 'xpassed'),
|
('xfail', 'XPASS', 'xpassed'),
|
||||||
|
|
Loading…
Reference in New Issue