I'm trying to use pytest to take in an id for a suite to run, load the suite from a db, and then generate the test cases in a parameterized fashion. The code below shows the gist of what I want to do, but errors with fixture 'case' not found
.
How can I parameterize case
with the ids that get returned from the db lookup?
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