generalize skipping
- rename pytest_xfail to pytest_skip - dynamic "skipif" and "xfail" decorators - move most skipping code to the plugin also coming with this commit: - extend mark keyword to accept positional args + docs - fix a few documentation related issues - leave version as "trunk" for now --HG-- branch : trunk
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
|
||||
pytest_plugins = "pytest_xfail", "pytest_pytester", "pytest_tmpdir"
|
||||
pytest_plugins = "skipping", "pytester", "tmpdir"
|
||||
|
||||
|
||||
@@ -14,12 +14,14 @@ def test_pytest_mark_api():
|
||||
assert f.world.x == 3
|
||||
assert f.world.y == 4
|
||||
|
||||
mark.world("hello")(f)
|
||||
assert f.world._0 == "hello"
|
||||
|
||||
py.test.raises(TypeError, "mark.some(x=3)(f=5)")
|
||||
|
||||
def test_mark_plugin(testdir):
|
||||
p = testdir.makepyfile("""
|
||||
import py
|
||||
pytest_plugins = "keyword"
|
||||
@py.test.mark.hello
|
||||
def test_hello():
|
||||
assert hasattr(test_hello, 'hello')
|
||||
|
||||
@@ -27,6 +27,12 @@ class TestSetupState:
|
||||
ss.teardown_all()
|
||||
assert not l
|
||||
|
||||
def test_teardown_exact_stack_empty(self, testdir):
|
||||
item = testdir.getitem("def test_func(): pass")
|
||||
ss = runner.SetupState()
|
||||
ss.teardown_exact(item)
|
||||
ss.teardown_exact(item)
|
||||
ss.teardown_exact(item)
|
||||
|
||||
class BaseFunctionalTests:
|
||||
def test_passfunction(self, testdir):
|
||||
|
||||
109
testing/pytest/plugin/test_pytest_skipping.py
Normal file
109
testing/pytest/plugin/test_pytest_skipping.py
Normal file
@@ -0,0 +1,109 @@
|
||||
import py
|
||||
|
||||
def test_xfail_decorator(testdir):
|
||||
p = testdir.makepyfile(test_one="""
|
||||
import py
|
||||
@py.test.mark.xfail
|
||||
def test_this():
|
||||
assert 0
|
||||
|
||||
@py.test.mark.xfail
|
||||
def test_that():
|
||||
assert 1
|
||||
""")
|
||||
result = testdir.runpytest(p)
|
||||
extra = result.stdout.fnmatch_lines([
|
||||
"*expected failures*",
|
||||
"*test_one.test_this*test_one.py:4*",
|
||||
"*UNEXPECTEDLY PASSING*",
|
||||
"*test_that*",
|
||||
"*1 xfailed*"
|
||||
])
|
||||
assert result.ret == 1
|
||||
|
||||
def test_skipif_decorator(testdir):
|
||||
p = testdir.makepyfile("""
|
||||
import py
|
||||
@py.test.mark.skipif("hasattr(sys, 'platform')")
|
||||
def test_that():
|
||||
assert 0
|
||||
""")
|
||||
result = testdir.runpytest(p)
|
||||
extra = result.stdout.fnmatch_lines([
|
||||
"*Skipped*platform*",
|
||||
"*1 skipped*"
|
||||
])
|
||||
assert result.ret == 0
|
||||
|
||||
def test_skipif_class(testdir):
|
||||
p = testdir.makepyfile("""
|
||||
import py
|
||||
class TestClass:
|
||||
skipif = "True"
|
||||
def test_that(self):
|
||||
assert 0
|
||||
def test_though(self):
|
||||
assert 0
|
||||
""")
|
||||
result = testdir.runpytest(p)
|
||||
extra = result.stdout.fnmatch_lines([
|
||||
"*2 skipped*"
|
||||
])
|
||||
|
||||
def test_getexpression(testdir):
|
||||
from _py.test.plugin.pytest_skipping import getexpression
|
||||
l = testdir.getitems("""
|
||||
import py
|
||||
mod = 5
|
||||
class TestClass:
|
||||
cls = 4
|
||||
@py.test.mark.func(3)
|
||||
def test_func(self):
|
||||
pass
|
||||
@py.test.mark.just
|
||||
def test_other(self):
|
||||
pass
|
||||
""")
|
||||
item, item2 = l
|
||||
assert getexpression(item, 'xyz') is None
|
||||
assert getexpression(item, 'func') == 3
|
||||
assert getexpression(item, 'cls') == 4
|
||||
assert getexpression(item, 'mod') == 5
|
||||
|
||||
assert getexpression(item2, 'just')
|
||||
|
||||
def test_evalexpression_cls_config_example(testdir):
|
||||
from _py.test.plugin.pytest_skipping import evalexpression
|
||||
item, = testdir.getitems("""
|
||||
class TestClass:
|
||||
skipif = "config._hackxyz"
|
||||
def test_func(self):
|
||||
pass
|
||||
""")
|
||||
item.config._hackxyz = 3
|
||||
x, y = evalexpression(item, 'skipif')
|
||||
assert x == 'config._hackxyz'
|
||||
assert y == 3
|
||||
|
||||
def test_importorskip():
|
||||
from _py.test.outcome import Skipped
|
||||
from _py.test.plugin.pytest_skipping import importorskip
|
||||
assert importorskip == py.test.importorskip
|
||||
try:
|
||||
sys = importorskip("sys")
|
||||
assert sys == py.std.sys
|
||||
#path = py.test.importorskip("os.path")
|
||||
#assert path == py.std.os.path
|
||||
py.test.raises(Skipped, "py.test.importorskip('alskdj')")
|
||||
py.test.raises(SyntaxError, "py.test.importorskip('x y z')")
|
||||
py.test.raises(SyntaxError, "py.test.importorskip('x=y')")
|
||||
path = importorskip("py", minversion=".".join(py.__version__))
|
||||
mod = py.std.types.ModuleType("hello123")
|
||||
mod.__version__ = "1.3"
|
||||
py.test.raises(Skipped, """
|
||||
py.test.importorskip("hello123", minversion="5.0")
|
||||
""")
|
||||
except Skipped:
|
||||
print(py.code.ExceptionInfo())
|
||||
py.test.fail("spurious skip")
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
|
||||
def test_xfail(testdir):
|
||||
p = testdir.makepyfile(test_one="""
|
||||
import py
|
||||
@py.test.mark.xfail
|
||||
def test_this():
|
||||
assert 0
|
||||
|
||||
@py.test.mark.xfail
|
||||
def test_that():
|
||||
assert 1
|
||||
""")
|
||||
result = testdir.runpytest(p)
|
||||
extra = result.stdout.fnmatch_lines([
|
||||
"*expected failures*",
|
||||
"*test_one.test_this*test_one.py:4*",
|
||||
"*UNEXPECTEDLY PASSING*",
|
||||
"*test_that*",
|
||||
])
|
||||
assert result.ret == 1
|
||||
|
||||
@@ -15,26 +15,6 @@ class TestRaises:
|
||||
def test_raises_function(self):
|
||||
py.test.raises(ValueError, int, 'hello')
|
||||
|
||||
def test_importorskip():
|
||||
from _py.test.outcome import Skipped
|
||||
try:
|
||||
sys = py.test.importorskip("sys")
|
||||
assert sys == py.std.sys
|
||||
#path = py.test.importorskip("os.path")
|
||||
#assert path == py.std.os.path
|
||||
py.test.raises(Skipped, "py.test.importorskip('alskdj')")
|
||||
py.test.raises(SyntaxError, "py.test.importorskip('x y z')")
|
||||
py.test.raises(SyntaxError, "py.test.importorskip('x=y')")
|
||||
path = py.test.importorskip("py", minversion=".".join(py.__version__))
|
||||
mod = py.std.types.ModuleType("hello123")
|
||||
mod.__version__ = "1.3"
|
||||
py.test.raises(Skipped, """
|
||||
py.test.importorskip("hello123", minversion="5.0")
|
||||
""")
|
||||
except Skipped:
|
||||
print(py.code.ExceptionInfo())
|
||||
py.test.fail("spurious skip")
|
||||
|
||||
def test_pytest_exit():
|
||||
try:
|
||||
py.test.exit("hello")
|
||||
|
||||
@@ -10,7 +10,7 @@ class TestParser:
|
||||
|
||||
def test_epilog(self):
|
||||
parser = parseopt.Parser()
|
||||
assert not parser.epilog
|
||||
assert not parser.epilog
|
||||
parser.epilog += "hello"
|
||||
assert parser.epilog == "hello"
|
||||
|
||||
@@ -76,15 +76,6 @@ class TestParser:
|
||||
args = parser.parse_setoption([], option)
|
||||
assert option.hello == "x"
|
||||
|
||||
def test_parser_epilog(self, testdir):
|
||||
testdir.makeconftest("""
|
||||
def pytest_addoption(parser):
|
||||
parser.epilog = "hello world"
|
||||
""")
|
||||
result = testdir.runpytest('--help')
|
||||
#assert result.ret != 0
|
||||
assert result.stdout.fnmatch_lines(["*hello world*"])
|
||||
|
||||
def test_parse_setoption(self):
|
||||
parser = parseopt.Parser()
|
||||
parser.addoption("--hello", dest="hello", action="store")
|
||||
@@ -109,3 +100,14 @@ class TestParser:
|
||||
option, args = parser.parse([])
|
||||
assert option.hello == "world"
|
||||
assert option.this == 42
|
||||
|
||||
@py.test.mark.skipif("sys.version_info < (2,5)")
|
||||
def test_addoption_parser_epilog(testdir):
|
||||
testdir.makeconftest("""
|
||||
def pytest_addoption(parser):
|
||||
parser.epilog = "hello world"
|
||||
""")
|
||||
result = testdir.runpytest('--help')
|
||||
#assert result.ret != 0
|
||||
assert result.stdout.fnmatch_lines(["*hello world*"])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user