Last active
November 21, 2017 11:02
-
-
Save alexche8/4e3a5adaa27b0b14f1bc591c692906f0 to your computer and use it in GitHub Desktop.
Django: Run tests on production/local database. Keeps database structure and data after.
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
# DJANGO VERSION: 1.10.7 |
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
python manage.py test--settings=path.to.test_settings --keepdb |
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
from django.test.testcases import TransactionTestCase | |
from django.test.runner import DiscoverRunner | |
class CustomTestRunner(DiscoverRunner): | |
def setup_databases(self, **kwargs): | |
pass | |
def teardown_databases(self, old_config, **kwargs): | |
pass | |
def teardown_test_environment(self, **kwargs): | |
pass | |
class TestSearch(TransactionTestCase): | |
def test_body(self): | |
# your tests | |
pass | |
def tearDown(self): | |
pass | |
def _post_teardown(self): | |
# don't remove data after test | |
pass |
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
DATABASES = { | |
'default': { | |
'ENGINE': 'engine', | |
'NAME': 'immortal_db', | |
'USER': 'user', | |
'PASSWORD': 'user', | |
'TEST': { | |
'NAME': 'immortal_db' | |
} | |
} | |
} | |
TEST_RUNNER = 'path.to.class.CustomTestRunner' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment