gpt4 book ai didi

python - 如何在 py.test 中重复测试模块?

转载 作者:行者123 更新时间:2023-11-28 20:54:54 24 4
gpt4 key购买 nike

我想重复一个测试模块N次。
顺序很重要。

test_stress.py 的内容

import pytest
@pytest.mark.usefixtures("class_setup_teardown")
class TestStressRobot:
def test_1(self):
print "\nstressing part 1..."
assert True

def test_2(self):
print "\nstressing part 2..."
assert True

def test_3(self):
print "\nstressing part 3..."
assert True

当我运行 py.test --repeat=2 时,输出是:

test_stress.pyTestStressRobot.test_1[0] ✓
test_stress.pyTestStressRobot.test_1[1] ✓
test_stress.pyTestStressRobot.test_2[0] ✓
test_stress.pyTestStressRobot.test_2[1] ✓
test_stress.pyTestStressRobot.test_3[0] ✓
test_stress.pyTestStressRobot.test_3[1] ✓

我不希望它在每个测试中重复,而是在每个测试模块中重复。

有可能有这样的东西吗?

test_stress.pyTestStressRobot.test_1[0] ✓
test_stress.pyTestStressRobot.test_2[0] ✓
test_stress.pyTestStressRobot.test_3[0] ✓
test_stress.pyTestStressRobot.test_1[1] ✓
test_stress.pyTestStressRobot.test_2[1] ✓
test_stress.pyTestStressRobot.test_3[1] ✓

最佳答案

尝试

pytestmark = [pytest.mark.usefixtures('module_scoped_fun')]

在模块级别使用模块范围的参数化 fixture ?

关于python - 如何在 py.test 中重复测试模块?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28564589/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com