Skip to content

Inconsistent behaviour of db mark #60

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

Closed
canni opened this issue Nov 29, 2013 · 2 comments
Closed

Inconsistent behaviour of db mark #60

canni opened this issue Nov 29, 2013 · 2 comments

Comments

@canni
Copy link

canni commented Nov 29, 2013

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.

@pelme
Copy link
Member

pelme commented Dec 16, 2013

Thanks for the report!

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!

@pelme
Copy link
Member

pelme commented Jul 25, 2015

  1. Is the expected behavior - explicit marking django_db is required
  2. This is a bug and should be improved, it is tracked in Improve failure when a database access happens from unittest.TestCase #234
  3. This is the expected behavior to be able to support existing Django test suites out of the box

I'm closing this, this issue, see #234 for follow up on the unittest2.TestCase problem

@pelme pelme closed this as completed Jul 25, 2015
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

2 participants