@pytest.mark.skip(reason="no way of currently testing this")
def test_example(faker):
print("nihao")
print(faker.words())
满足条件时跳过
def test_example():
a=1
if a>0:
pytest.skip("unsupported configuration")
import sys
@pytest.mark.skipif(sys.version_info < (3, 10), reason="requires python3.10 or higher")
def test_function():
...
@pytest.mark.xfail
def test_function():
...
def test_function():
if not valid_config():
pytest.xfail("failing configuration (but should work)")
import pytest
@pytest.mark.parametrize(
("n", "expected"),
[
(1, 2),
pytest.param(1, 0, marks=pytest.mark.xfail),
pytest.param(1, 3, marks=pytest.mark.xfail(reason="some bug")),
(2, 3),
(3, 4),
(4, 5),
pytest.param(
10, 11, marks=pytest.mark.skipif(sys.version_info >= (3, 0), reason="py2k")
),
],
)
def test_increment(n, expected):
assert n + 1 == expected