【发布时间】:2020-12-22 04:10:00
【问题描述】:
我想重复一个测试模块 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] ✓
【问题讨论】:
-
如果顺序很重要,您可能会错误地组织测试。看看例如stackoverflow.com/q/21764473/3001761
-
非常感谢您的帮助!