有没有办法指定从文件运行哪些 pytest 测试?

编程入门 行业动态 更新时间:2024-10-11 17:19:25
本文介绍了有没有办法指定从文件运行哪些 pytest 测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

有没有办法从文件中选择 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 测试?

本文发布于:2023-06-03 23:41:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/484985.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:没有办法   文件   测试   pytest

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!