Description
I have a periodically-increasing set of regression test-cases in my test database, but I don't see a documented way to look in the django db and use that data to set the length of my parameterized 'regression_test_data' fixture. As a hack, before 3.0, inside 'pytest_generate_tests' I would check if regression tests are being run and, if so, hit the database using the django db manager to determine the number of regression tests, but even this hack fails during collection on 3.0 with 'Failed: Database access not allowed, use the "django_db" mark to enable it.'
Ideally test generation referenced from a django_db test could be enhanced to automatically allow db access. As an added bonus it would be great if any collection of a django_db test could be completely skipped if the command-line is run to ignore tests marked django_db. If this were implemented in version X.Y, then I could do something like:
# test_my_regression.py
@pytest.mark.django_db
def test_my_regression_for_my_function(my_regression_fixture): ...
# conftest.py
def pytest_generate_tests(metafunc):
if 'my_regression_fixture' in metafunc.fixturenames:
# This code won't get called during fast tests, because none of
# my fast tests use my_regression_fixture, and pytest X.Y is smart
# enough to not even call pytest_generate_tests on those skipped tests.
# pytest X.Y checks for django_db tag on test_my_regression_for_my_function,
# and says 'OK, you can use db', rather than raise error
regressions = Regression.objects.filter(...)
metafunc.parametrize('my_regression_fixture', regressions)
-Rolf