有没有办法从文件中选择 pytest 测试来运行?例如,包含要执行的测试列表的文件 foo.txt:
Is there a way to select pytest tests to run from a file? For example, a file foo.txt containing a list of tests to be executed:
tests_directory/foo.py::test_001 tests_directory/bar.py::test_some_other_test或者,有没有办法用pytest从不同的目录中选择多个测试,在测试名称中没有共同的模式?
Or, is there a way to select multiple tests, having no common pattern in test name, from different directories with pytest?
pytest -k 允许单个模式.
一种选择是针对每个测试使用 pytest.mark,但我的要求是运行来自不同文件的不同测试组合.
One option is to have a pytest.mark against each test, but my requirement is to run different combination of tests from different files.
有没有办法为每个模式指定多个模式和一个测试文件名?
Is there a way to specify multiple patterns and a test file name for each pattern?
或
有没有办法在文件中指定确切的测试路径并将该文件作为输入提供给 pytest?
Is there a way to specify the exact test paths in a file and feed that file as an input to pytest?
或
是否有可以用于此目的的钩子函数?
Is there a hook function that can be utilized for this purpose?
推荐答案您可以使用 -k 选项以运行不同模式的测试用例:
You can use -k option to run test cases with different patterns:
py.test tests_directory/foo.py tests_directory/bar.py -k 'test_001 or test_some_other_test'这将运行名为 test_001 和 test_some_other_test 的测试用例,取消选择其余的测试用例.
This will run test cases with name test_001 and test_some_other_test deselecting the rest of the test cases.
注意:这将选择以test_001 或 test_some_other_test 开头的任何测试用例.例如,如果您有测试用例 test_0012,它也会被选中.
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.
更多推荐
有没有办法指定从文件运行哪些 pytest 测试?
发布评论