python - Py.test 反复循环测试

标签 python pytest

我正在尝试重复测试 N 次(收集的相同测试)。

原因:通过这样做,我想看看测试速度是否降低了,或者我可以收集一个参数的“平均时间”,然后传递另一个参数并再次获得“平均时间”。

我的理解是使用 def pytest_runteSTLoop() Hook ,但是我遇到了麻烦。

这是我的钩子(Hook)代码:

def pytest_runtestloop(session):
    repeat = int(session.config.option.repeat)
    assert isinstance(repeat, int), "Repeat must be an integer"
    for i in range(repeat): #@UnusedVariable                      
        session.config.pluginmanager.getplugin("main").pytest_runtestloop(session)

    return True

问题是“设置”只在第一次运行: 例如:

class TestSomething(object):

    @classmethod
    @pytest.fixture(scope = "class", autouse = True)
    def setup(self):
        //setup function

    def test_something(self):
        //test function

这里 setup 只会在第一个周期被调用,如果我设置 session.config.option.repeat 到 2

我做错了什么?有更好的方法吗?

最佳答案

似乎 pytest-2.3.4 在内部保持某种状态,以防止固定装置再次运行。 pytest_runtest_loop 编写时并未考虑您的用例。您可以提交一个关于它的“错误”问题,我们可以看到我们可以做些什么来修复它。 (我快速查看但无法立即看出问题所在,需要更多探索)。

关于python - Py.test 反复循环测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15030010/

相关文章:

pytest - 在 setup_module 中使用 funcargs

python - 在 py.test 中的每个测试之前和之后运行代码?

python - 为什么测试功能看不到我的 py.test 装置?

python-3.x - 在现有 Python/Flask 应用程序上实现代码覆盖率和单元测试

python - Python 中的 fitdist 和 histfit 相当于什么?

python - 返回与 python 重复出现的正则表达式匹配

python - 在 Spark 本地模式下包含包

python - 使用 python/win32 从/向剪贴板复制和粘贴

python - 如何使用可变长度字符串解码 TFRecord 数据样本?

python - pymongo 中的 collection.getIndexes() shell 命令的等价物是什么?