我正在尝试使用 pytest 获取要运行的套件的 id,从数据库加载套件,然后以参数化方式生成测试用例。下面的代码显示了我想要做的事情的要点,但是fixture 'case' not found
.
如何case
使用从数据库查找返回的 id 进行参数化?
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "test_harness.settings")
application = get_wsgi_application()
from unitrunner.models import TestSuiteModel as SuiteModel
def pytest_addoption(parser):
parser.addoption("--suite", action="append", default=[],
help="Suite ID to evaluate")
def pytest_generate_tests(metafunc):
if 'suite' in metafunc.fixturenames:
suite_id = metafunc.fixturenames['suite']
this_suite = SuiteModel.objects.get(id=suite_id)
test_cases = this_suite.testCases.all()
metafunc.parametrize(
"case",
[item.id for item in test_cases]
)
def test_case(case):
print(case)
assert False