【问题标题】:How can I repeat a test module in py.test?如何在 py.test 中重复测试模块?
【发布时间】: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] ✓

【问题讨论】:

标签: python testing pytest


【解决方案1】:

试试

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

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

【讨论】:

    【解决方案2】:

    试试这个:

    pytest --flake-finder --flake-runs=runs

    https://github.com/dropbox/pytest-flakefinder

    【讨论】:

    • 我试过 flakefinder,它没有按照编写测试的顺序执行测试。
    猜你喜欢
    • 2014-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-02
    • 2019-06-08
    • 1970-01-01
    相关资源
    最近更新 更多