-
Notifications
You must be signed in to change notification settings - Fork 345
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
Easy fixture loading #57
Comments
A straightforward way to load fixtures that works with the regular module/class level setup methods would be very welcome. I have a bunch a tests that depend on a fixture or set of fixtures to be loaded. With a single test it's easy: from django.core.management import call_command
import pytest
def test_whatever():
call_command('loaddata', 'whatever.json')
# Test code that interacts with DB However, if I have another test function that depends on the same fixture I'm not sure how to structure my code. Initially I thought I would use py.test's @pytest.mark.django_db()
def setup_module(module):
call_command('loaddata', 'whatever.json')
@pytest.mark.django_db()
def test_whatever():
# Test code that interacts with DB But that does not load the fixture. Nor does: @pytest.mark.django_db()
class TestWhatever:
@classmethod
def setup_class(cls):
call_command('loaddata', 'whatever.json')
def test_whatever(self):
# Test code that interacts with DB So how do I structure my code so that I load my fixture once, before any tests are run. I'd rather not load them from within a specific test as the order in which the tests are run is unspecified. Eg, which of the two or more tests should load the fixtures? |
Currently it is not possible to load fixtures in the session/module/class scope, you must do it in the function scope. I have a plan to improve database transaction handling and this will be possible when that is done. Then this issue can probably be fixed by documenting the steps to make Django fixture loading in multiple scopes work. |
This will be solved by #258 |
Re-opening this bug. Sometimes you need to test your fixtures, would be very interesting to being able to load them on acceptance tests.
The text was updated successfully, but these errors were encountered: