You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I was upgrading my project tests to use pytest_django plugin I've ran into this issue:
Currently @pytest.mark.django_db has (at least) 3 different behaviours
When using simple function based test you forget to add marker, you get: Failed: Database access not allowed, use the "django_db" mark to enable
When using tests as methods on unitest2.TestCase subclass you forget to add db marker, you get: ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the NAME value.
When using test as methods on django.test.TestCase subclass, the marker is completely ignored (You're always allowed yo use DB inside)
Probably this should be documented as a feature ;) or fixed to behave concisely for all cases.
The text was updated successfully, but these errors were encountered:
The idea is that django.test.TestCase should work out of the box just as with the standard test runner, without adding any extra markers or requesting fixtures. Any other tests should not be able to access the database unless specified by the pytest.mark.django_db mark or the db fixture.
The documentation can certainly be improved here, a PR with these changes would be more than welcome! :)
The ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the NAME value. error is probably a bug, it should really report Failed: Database access not allowed, use the "django_db" mark to enable to be consistent.
I tried to reproduce this with a test case, but failed: master...unittest2
Can you provide additional details on how to trigger that error message? Thanks!
When I was upgrading my project tests to use
pytest_django
plugin I've ran into this issue:Currently
@pytest.mark.django_db
has (at least) 3 different behavioursFailed: Database access not allowed, use the "django_db" mark to enable
unitest2.TestCase
subclass you forget to add db marker, you get:ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the NAME value.
django.test.TestCase
subclass, the marker is completely ignored (You're always allowed yo use DB inside)Probably this should be documented as a feature ;) or fixed to behave concisely for all cases.
The text was updated successfully, but these errors were encountered: