pytest常用命令行

pytest --collect-only

使用--collect-only选项可以展示在给定的配置下哪些测试用例会被运行

pytest -k

-k可以通过表达式运行指定的测试用例

比如pytest -k “asdict or defaults”,就指定运行test_asdict()和test_defaults()。

pytest  -m

marker用于标记测试并分组,以便快速选中并运行。

使用-m选项可以用表达式指定多个标记名。

使用-m “mark1 and mark2” 可以同时选中带有这两个标记的所有测试用例。

使用-m "mark1 and not mark2 " 会选中带有mark1的测试用例,过滤掉带有mark2的测试用例

使用-m “mark1 or mark2” 会选中带有mark1或者mark2的所有测试用例

-x

使用-x,在执行测试用例时,遇到测试失败,就会全局停止

--maxfail=num

使用--maxfail=2,可以指定pytest失败2次后再停止

--lf(--last-failed)

当一个或多个测试失败时,希望能够定位到最后一个失败的测试用例重新运行,可以使用--lf选项

--ff(--failed-first)选项

--ff选项与--lf选项作用基本相同,不同之处在于--ff会运行完剩余的测试用例

原文地址:https://www.cnblogs.com/ruguokeyi/p/11885110.html