我有一个充满数据文件的目录,用于测试,并且我使用以下代码来加载它们:
@pytest.fixture(scope="function")
def test_image_one():
return load_image("test_image_one.png")
随着测试套件的增长,这变得难以维护。是否有一种可以编程创建固定装置的方法?理想情况下,它应该像这样:
for fname in ["test_image_one", "test_image_two", ...]:
def pytest_fixutre_function():
return load_image("{}.png".format(fname))
pytest.magic_create_fixture_function(fname, pytest_fixutre_function)
有没有一种方法可以实现这个?