标记只能应用于测试,对fixtures没有影响。
在pytest.ini文件中注册marker标记
[pytest]
markers =
slow: marks tests as slow (deselect with '-m "not slow"')
serial
:冒号后面的都是可选描述
已注册的标记不会引发警告
使用@ pytest.mark.name_of_the_mark装饰器应用的未注册标记(未知标记)将始终发出警告
当在命令行使用 --strict-markers 参数时,未注册标记将触发error
---------------------------------
@pytest.mark.run:
指定测试的顺序信息。由pytest-ordering提供
specify ordering information for when tests should run in relation to one another. Provided by pytest-ordering. See also: http://pytest-ordering.readthedocs.org/
@pytest.mark.filterwarnings(warning):
在测试中添加警告过滤,过滤某些警告
add a warning filter to the given test. see https://docs.pytest.org/en/stable/warnings.html#pytest-mark-filterwarnings
@pytest.mark.skip(reason=None):
总是跳过测试功能,可选原因 。
示例:skip(reason =“目前无法对此进行测试”)
skip the given test function with an optional reason. Example: skip(reason="no way of currently testing this") skips the test.
@pytest.mark.skipif(condition, ..., *, reason=...):
如果满足特定条件,则跳过测试功能
示例:skipif(sys.platform =='win32')
skip the given test function if any of the conditions evaluate to True. Example: skipif(sys.platform == 'win32') skips the test if we are on the win32 platform. See https://docs.pytest.org/en/stable/reference.html#pytest-mark-skipif
@pytest.mark.xfail(condition, ..., *, reason=..., run=True, raises=None, strict=xfail_strict):
如果满足特定条件,则会产生“预期的失败”结果。可选指定原因
如果不想执行测试功能,则将run= False。
如果只期望特定的例外情况,则可以在raises中列出他们,并且如果测试以其他方式失败,将被报告为真正的失败。
mark the test function as an expected failure if any of the conditions evaluate to True. Optionally specify a reason for better reporting and run=False if you don't even want to execute the test function. If only specific exception(s) are expected, you can list them in raises, and if the test
fails in other ways, it will be reported as a true failure. See https://docs.pytest.org/en/stable/reference.html#pytest-mark-xfail
@pytest.mark.parametrize(argnames, argvalues):
对同一测试功能执行多次调用,依次传递不同的参数。
如果argnames仅指定一个名称,则argvalues通常需要是值的列表;如果argnames指定多个名称,则argvalues的值通常是元组列表。
示例:@parametrize('arg1',[1,2])将导致函数的两次调用,一次调用arg1 = 1,
另一次arg1 = 2。
call a test function multiple times passing in different arguments in turn. argvalues generally needs to be a list of values if argnames specifies
only one name or a list of tuples of values if argnames specifies multiple names. Example: @parametrize('arg1', [1,2]) would lead to two calls of the decorated test function, one with arg1=1 and
another with arg1=2.see https://docs.pytest.org/en/stable/parametrize.html for more info and examples.
@pytest.mark.usefixtures(fixturename1, fixturename2, ...):
将测试标记为需要所有指定的fixtures。
mark tests as needing all of the specified fixtures. see https://docs.pytest.org/en/stable/fixture.html#usefixtures
@pytest.mark.tryfirst:
标记一个hook实现函数,以便插件机制将尝试首先/尽早调用它
mark a hook implementation function such that the plugin machinery will try to call it first/as early as possible.
@pytest.mark.trylast:
标记一个hook实现函数,以便插件机制将尝试最后/尽晚调用它
mark a hook implementation function such that the plugin machinery will try to call it last/as late as possible.