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

Easy fixture loading #57

Open
santagada opened this issue Nov 18, 2013 · 3 comments
Open

Easy fixture loading #57

santagada opened this issue Nov 18, 2013 · 3 comments

Comments

@santagada
Copy link

Re-opening this bug. Sometimes you need to test your fixtures, would be very interesting to being able to load them on acceptance tests.

@gkoller
Copy link

gkoller commented Mar 28, 2014

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 setup_module(module) function as in:

@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?

@pelme
Copy link
Member

pelme commented Jul 25, 2015

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.

@pelme
Copy link
Member

pelme commented Jul 3, 2016

This will be solved by #258

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

3 participants