Automated tests 需要使用py.test动态运行标记的测试
我正在寻找一种在运行时运行选择性测试的方法。发现可以使用Automated tests 需要使用py.test动态运行标记的测试,automated-tests,pytest,Automated Tests,Pytest,我正在寻找一种在运行时运行选择性测试的方法。发现可以使用@pytest.mark标记每个测试 导入。。。 @pytest.mark.feature1 @pytest.mark.priority1 或者类似:@pytest.mark(Feature.feature1,Priority.priority2) def m1 def m2 .. 现在我需要运行标记为feature1的测试脚本,而不提供脚本名称。 类似(不确定命令) 它应该选择测试套件中标记为feature1的所有脚本,因为其他脚本也可
@pytest.mark
标记每个测试
导入。。。
@pytest.mark.feature1
@pytest.mark.priority1
或者类似:@pytest.mark(Feature.feature1,Priority.priority2)
def m1
def m2
..
现在我需要运行标记为feature1
的测试脚本,而不提供脚本名称。
类似(不确定命令)
它应该选择测试套件中标记为feature1
的所有脚本,因为其他脚本也可能标记为feature2..n
请建议:
谢谢 我想你在找
这将根据您输入的条件跳过测试。您可以在if条件下使用字符串跳过所需的测试Ok,在这种情况下,这可能就是答案pytest-k string选择名称中包含该字符串的所有测试并运行它我想您要找的是py.test的-m选项 使用不同的标签标记测试(使用@pytest.mark.label,其中标签为feature1或任何您想要的内容)后,可以使用以下方式运行所有feature1标记的测试:
py.test -m feature1
这将仅运行标有“feature1”标签的测试
有标记的测试可以组合在一起:
py.test -m "feature1 or feature2"
或跳过使用而不是,例如
py.test -m "not (feature1 or feature2)"
Thakd的评论MAchintosh_89,但我希望有脚本上的自动标签,用于动态选择。Skipif将跳过脚本。这将一直工作到一个范围。但我的用例是,我希望运行所有具有feature1、高优先级且标记为smoke脚本的脚本。因此,每个脚本可能都有类似于@pytest.marks的内容(feature1,high,Smoke)。。请再看一看“”。。我找到了一些解决上述问题的方法,但也有一些问题。
py.test -m "not (feature1 or feature2)"