Python 3.x pytest基准:在每个基准迭代上运行安装程序

Python 3.x pytest基准:在每个基准迭代上运行安装程序,python-3.x,pytest,pytest-benchmark,Python 3.x,Pytest,Pytest Benchmark,我正在尝试使用pytest基准测试我们的js捆绑包的捆绑过程。为了准确处理,目标目录需要为空。我试着在每次运行时使用pedantic setup参数来清理它,但这只在基准测试初始化时运行,而不是在运行之间运行。这是我最后一次尝试的代码: import shutil import os import pytest def clean_bundles(): print("Cleaning bundles") shutil.rmtree(os.path.abspath('precom

我正在尝试使用pytest基准测试我们的js捆绑包的捆绑过程。为了准确处理,目标目录需要为空。我试着在每次运行时使用pedantic setup参数来清理它,但这只在基准测试初始化时运行,而不是在运行之间运行。这是我最后一次尝试的代码:

import shutil
import os
import pytest

def clean_bundles():
    print("Cleaning bundles")
    shutil.rmtree(os.path.abspath('precompiled'), True)

def bundle(gulpfile):
    os.system("gulp --gulpfile %s createBundles" % gulpfile)

def test_bundle(benchmark):
    benchmark.pedantic(lambda: bundle("gulpfile.js"), setup=clean_bundles(), rounds=5, iterations=1)

是否在每次迭代之间运行clean而不将其作为基准测试结果的一部分?

如果将
clean_bundles
作为自动使用的fixture(添加
@pytest.fixture(autouse=True)
之前
定义clean_bundles():
),会发生什么?我不确定它是否会在基准迭代之间执行,但值得一试。遗憾的是,它不起作用,它只是在测试本身之前运行,而不是在每次迭代之间运行。