cmd> pip install pytest
import pytest
@pytest.mark.run(order=2)
def test_1():
assert 2 > 1
@pytest.mark.run(order=1)
def test_2():
assert 3 == 4
import pytest
if __name__ == "__main__":
pytest.main(['-v','-s', '-k', 'test_a', '--html= report/test2.html'])
@pytest.mark.skip(reason=None)
@pytest.mark.skip(condition, reason="模块未开发好,跳过执行")
@pytest.mark.xfail(reson="预期失败")
@pytest.mark.xfail(reson="预期失败", run=False)
import pytest
@pytest.fixture()
def con():
print("before test ")
yield
print("after test")
@pytest.mark.run(order=2)
def test_1():
assert 2 > 1
@pytest.mark.usefixtures('con')
def test_2():
assert 1 == 1
import pytest
@pytest.fixture()
def con():
print("before test ")
yield
print("after test")
@pytest.mark.run(order=2)
def test_1():
assert 2 > 1
@pytest.mark.smoke
@pytest.mark.usefixtures('con')
def test_2():
assert 1 == 1
@pytest.mark.smoke
def test_4():
assert 1 == 1
@pytest.mark.smoke
def test_5():
assert 1 == 1
pytest -v -m 'not smoke'
pytest -v -m smoke
import pytest
from _pytest.python_api import approx
def test_one():
assert 0.3 - 0.2 == approx(0.1)
目录所示
pytest --alluredir=./allure-results
allure serve ./allure-results