@pytest.mark.name_of_the_mark,注册标记使用方法

摘要:
用法@pytest.mark.name_of_the_mark,其中name_of_the _mark是用户定义标记的名称。例如,定义了以下三个标记。方法和函数可以标记为#@文件:test_001.pyimportpytest@pytest.mark.testaclassTestaddbook:@pytest.mark.addbook01deftest _ 01(self):打印('打印

使用方法

@pytest.mark.name_of_the_mark,其中name_of_the_mark是自定义标记的名字,举个例子,下面定义了3个,对方法、函数都可以进行标记

# @File : test_001.py
import pytest

@pytest.mark.testa
class Testaddbook:
    @pytest.mark.addbook01
    def test_01(self):
        print('打印01')

    @pytest.mark.addbook02
    def test_02(self):
        print('打印02')

1、在Terminal终端输入命令:pytest -sq test_001.py    ,执行全部

@pytest.mark.name_of_the_mark,注册标记使用方法第1张

 2、在Terminal终端输入命令:pytest -sq test_001.py -m=addbook02   ,执行标记名=addbook02的

@pytest.mark.name_of_the_mark,注册标记使用方法第2张

3、 在Terminal终端输入命令:pytest -sq test_001.py::Testaddbook::test_01  ,用两个冒号分隔表示需要执行的类名或函数,按路径写,执行test_01

配置文件

pytest.ini文件需要注册自定义标记

[pytest]
markers =
    testa
    addbook01
    addbook02

如果不注册,就会出现警告:PytestUnknownMarkWarning: Unknown pytest.mark.addbook02 - is this a typo? You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/stable/mark.html

如果需要检查是否所有标记都已经注册了,那么可以增加--strict 来加强验证,这时任何未知标记都会报错,如修改pytest.int,少了一个addbook02

[pytest]
markers =
    testa
    addbook01

 1、在Terminal终端输入命令:pytest -sq test_001.py --strict -m=addbook02

@pytest.mark.name_of_the_mark,注册标记使用方法第3张

免责声明:文章转载自《@pytest.mark.name_of_the_mark,注册标记使用方法》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇关于HTML的简述WPF:设置弹出子菜单的是否可用状态及效果下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

pytest框架(四)

测试用例setup和teardown 代码示例一 1 #coding=utf-8 2 importpytest 3 4 5 defsetup_module(): 6 print("setup_module:整个.py模块只执行一次") 7 print("比如:所有用例开始前只打开一次浏览器") 8 9 10 defteardown...

pytest自学第二期

好,现在开始学习pytest第二章2 pytest初级用法2.1 通过python解释器调用 pytest 在控制台输入命令:   python -m pytest 文档说这种方式相当于直接调用 pytest,唯一的不同是这样调用会把当前目录添加到sys.path (这句是重点,重点是啥,我不知道,   我不知道这有什么用c 以后就这样,如果有自己学过但是...

pytest框架(一)

代码示例一 1 #coding=utf-8 2 3 deffunc(x): 4 return x + 1 5 6 7 deftest_answer(): 8 assert func(3) == 5 运行结果 E:pyYouYoupytest_demo>pytest test_sample.py ================...

pytest文档40-pytest.ini配置用例查找规则(面试题)

前言 面试题:pytest如何执行不是test开头的用例?如执行 xxx_*.py这种文件的用例。 pytest.ini 配置文件可以修改用例的匹配规则。 pytest命令行参数 cmd打开输入pytest -h 查看命令行参数找到 [pytest] ini-options python_files (args) 匹配 python 用例文件, 如tes...

Python:Python 自动化测试框架 unittest 和 pytest 对比

一、用例编写规则     1.unittest提供了test cases、test suites、test fixtures、test runner相关的类,让测试更加明确、方便、可控。使用unittest编写用例,必须遵守以下规则:   (1)测试文件必须先import unittest   (2)测试类必须继承unittest.TestCase   (...

pytest文档70-Hook钩子函数完整API总结

前言 pytest 的钩子函数有很多,通过钩子函数的学习可以了解到pytest在执行用例的每个阶段做什么事情,也方便后续对pytest二次开发学习。 详细文档可以查看pytest官方文档https://docs.pytest.org/en/latest/reference.html#hooks 钩子函数总结 第一部分:setuptools 引导挂钩要求足够...