Pytest

测试文件的命名规则

1.测试文件应该命名为test_<something>.py或者<something>_test.py

2.测试类应该命名为Test<something>.py

3.测试函数和测试类方法应该命名为test_<something>

Pytest 基础命令

pytest --hlep 可以查看pytest相关命令

import pytest

@pytest.mark.smoke
def test_mark_smoke():
    print('the aim is test mark smoke')


@pytest.mark.get
@pytest.mark.smoke
def test_mark_get_smoke():
    print('the aim is testing mark smoke and get')

只需要在命令中指定-m mark_name 就可以运行

比如Pycharm 的Terminal中输入pytest -v -m smoke test.py

跳过测试pytest.mark.skip(reason='misunderstood the API')

标记预期失败的测试pytest.mark.xfail(reason= misunderstood the API)
xfail表示的是预期会失败,但实际上也失败了,xpass表示的是预期会失败,但实际上是运行并没有失败

上一篇:如何实现单机大规模并发SIP语音呼叫?


下一篇:django-apscheduler 实现定时任务详解