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

本文介绍了如何在Pytest中使用`@pytest.mark.smoke`标记进行冒烟测试,包括标记定义、配置文件设置以及运行带有指定标签的测试用例。示例展示了如何在测试代码中应用标记并查看运行结果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值