5π
β
I donβt know about nose, but here is how to run against and existing db with django (1.6) unit tests.
from django.test.runner import DiscoverRunner
from django.db import transaction
class ExistingDBTestRunner(DiscoverRunner):
def run_tests(self, test_labels, extra_tests=None, **kwargs):
self.setup_test_environment()
suite = self.build_suite(test_labels, extra_tests)
#old_config = self.setup_databases()
result = self.run_suite(suite)
#self.teardown_databases(old_config)
self.teardown_test_environment()
return self.suite_result(suite, result)
Then in settings.py
if 'test' in sys.argv:
TEST_RUNNER = '<?>.ExistingDBTestRunner'
# alternative db settings?
It will be a little different in older versions of django. Also, you may need to override _fixture_setup and _fixture_teardown in your test cases to pass.
The above code will connect to a preexisting database but since each test is wrapped in a transaction the changes wonβt be available to other connections (like the celery worker). The easiest way to disable transactions is to subclass from unittest.TestCase
instead of django.test.TestCase
.
π€joshua
0π
Have you had a look at django-nose? It seems like it would be the right tool for the job.
π€David
- [Django]-How to serve django static files on heroku with gunicorn
- [Django]-How to fix circular importing?
- [Django]-How use python-docx to stream a file from template
Source:stackexchange.com