+-
python – 有没有办法指定从文件运行哪些pytest测试?
有没有办法选择pytest测试从文件运行?
例如,包含要执行的测试列表的文件foo.txt:

tests_directory/foo.py::test_001
tests_directory/bar.py::test_some_other_test

要么
有没有办法从pytest的不同目录中选择多个测试,在测试名称中没有共同的模式?

py.test -k< pattern>允许单一模式.

一种选择是针对每个测试使用pytest.mark,但我的要求是运行来自不同文件的不同测试组合.

有没有办法为每个模式指定多个模式和测试文件名?
或者有没有办法在文件中指定确切的测试路径并将该文件作为pytest的输入提供?
要么
是否有可用于此目的的钩子功能?

最佳答案
您可以使用 -k option运行具有不同模式的测试用例:

py.test tests_directory/foo.py tests_directory/bar.py -k 'test_001 or test_some_other_test'

这将运行名为test_001的测试用例和test_some_other_test,以取消选择其余的测试用例.

Note: This will select any test case starting with test_001 or test_some_other_test. For example, if you have test case test_0012 it will also be selected.

点击查看更多相关文章

转载注明原文:python – 有没有办法指定从文件运行哪些pytest测试? - 乐贴网