Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No transaction support despite transactional_db (edge case of indirect parametrization) #1157

Open
scur-iolus opened this issue Oct 16, 2024 · 0 comments

Comments

@scur-iolus
Copy link

scur-iolus commented Oct 16, 2024

I've got tests which rely on a database with initial data (which is possible as explained here). I want to check that the initial data are present as expected and that my custom setup/teardown functions work well. Whether I use db (TestCase) or transactional_db (TransactionTestCase) should not matter in my test suite.

Thus, I wanted to use indirect parametrization as suggested here, in order not to write twice the same tests (DRY)...

@pytest.mark.parametrize("db_access", ["db", "transactional_db"], indirect=True)
class TestInitialData:
    @pytest.fixture(autouse=True)
    def db_access(self, request):
        return request.getfixturevalue(request.param)

    def test_example(self):
        pass

    # many other tests

No error is raised in this example, but it turns out (though that was hard to notice) that it doesn't work as expected: all tests use django.test.TestCase and are run twice without transaction support.

Admittedly, that's an edge case, but after having carefully read the documentation of pytest, pytest-django and django itself, I think it can be considered a bug.

I would say that the issue stems from the implementation of pytest_django.fixtures._django_db_helper which don't take into account indirect parametrization. Am I missing something?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant