pytest-dev / pytest-django

A Django plugin for pytest.
https://pytest-django.readthedocs.io/
Other
1.33k stars 341 forks source link

Upgrading to pytest 7 breaks django_db mark, and doesn't support pyproject.toml? #992

Closed chris-erickson closed 8 months ago

chris-erickson commented 2 years ago

Once updating to Pytest 7 from 6.2.5, tests that work in pytest < 7 fail with:

RuntimeError: Database access not allowed, use the "django_db" mark, or the "db" or "transactional_db" fixtures to enable it.

and to configure the settings file, the only thing that worked was leaving a pytest.ini behind with only this setting (I've migrated the rest to pyproject.toml)

[pytest]
DJANGO_SETTINGS_MODULE = my_app.settings.test

Is this a supported configuration yet, with the settings module in a pyproject.toml?

HansBambel commented 1 year ago

You can put this config in your pyproject.toml as well under:

[tool.pytest.ini_options]
DJANGO_SETTINGS_MODULE = "my_app.settings"
bluetech commented 8 months ago

@HansBambel got it right!