Last active
December 18, 2015 10:59
-
-
Save mikeywaites/5772578 to your computer and use it in GitHub Desktop.
load django fixture sets on a test by test basis
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Decorate a method inside of a django TestCase test runner instance to allow you to load fixtures on a per test basis | |
Useage:: | |
from tests.decorators import load_fixtures | |
MyTestCase(TestCase): | |
@load_fixtures(['fixtures.json']) | |
def test_load_fixtures(self): | |
self.assertTrue() | |
... | |
""" | |
from functools import wraps | |
from django.utils.decorators import available_attrs | |
def load_fixtures(fixtures): | |
def decorator(test_fn): | |
def _wrapped(test_case, *args, **kwargs): | |
test_case.fixtures = fixtures | |
test_case._fixture_setup() | |
test_case.fixtures = [] | |
return test_fn(test_case, *args, **kwargs) | |
return wraps(test_fn, assigned=available_attrs(test_fn))(_wrapped) | |
return decorator | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment