【pytest】 标记冒烟用例 @pytest.mark.smoke

1. 使用 @pytest.mark.smoke 标记用例


import pytest
class Test_Smoke:
    def test_01(self):
        assert 1+1==2
    @pytest.mark.smoke
    def test_02(self):
        assert 1+2==1

    @pytest.mark.smoke
    def test_03(self):
        assert 1 + 2 == 3

2.配置文件pytest.ini

[pytest]
markers =
	smoke

3.  运行指定标签  运行指定标签 pytest -m "标记名"

#----------------------------冒烟用例标记--------------------------------------
    pytest.main(['-s', '-v','-m smoke','./somke_test', '--html=./report/result.html'])

4. 运行结果

============================= test session starts =============================
platform win32 -- Python 3.10.9, pytest-7.1.2, pluggy-1.0.0 -- D:\software\python3\anconda3\python.exe
cachedir: .pytest_cache
metadata: {'Python': '3.10.9', 'Platform': 'Windows-10-10.0.19045-SP0', 'Packages': {'pytest': '7.1.2', 'pluggy': '1.0.0'}, 'Plugins': {'anyio': '3.5.0', 'base-url': '2.0.0', 'html': '4.0.2', 'metadata': '3.0.0', 'rerunfailures': '12.0'}, 'JAVA_HOME': 'D:\\software\\Java\\jdk1.8.0_151'}
rootdir: E:\data\web测试\Selenium3自动化测试实战——基于Python语言\mycode\pytest_example, configfile: pytest.ini
plugins: anyio-3.5.0, base-url-2.0.0, html-4.0.2, metadata-3.0.0, rerunfailures-12.0
collecting ... collected 3 items / 1 deselected / 2 selected

somke_test/test_smoke.py::Test_Smoke::test_02 FAILED
somke_test/test_smoke.py::Test_Smoke::test_03 PASSED

================================== FAILURES ===================================
_____________________________ Test_Smoke.test_02 ______________________________

self = <test_smoke.Test_Smoke object at 0x0000014593190F10>

    @pytest.mark.smoke
    def test_02(self):
>       assert 1+2==1
E       assert (1 + 2) == 1

somke_test\test_smoke.py:8: AssertionError
- Generated html report: file:///E:/data/web%E6%B5%8B%E8%AF%95/Selenium3%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95%E5%AE%9E%E6%88%98%E2%80%94%E2%80%94%E5%9F%BA%E4%BA%8EPython%E8%AF%AD%E8%A8%80/mycode/pytest_example/report/result.html -
=========================== short test summary info ===========================
FAILED somke_test/test_smoke.py::Test_Smoke::test_02 - assert (1 + 2) == 1
================== 1 failed, 1 passed, 1 deselected in 0.34s ==================

Process finished with exit code 0

猜你喜欢

转载自blog.csdn.net/oDianZi1234567/article/details/133062748