Is there a possibility to write django unittests without setting up a db? I want to test business logic which doesn’t require the db to set up. And while it is fast to setup a db, I really don’t need it in some situations.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can subclass DjangoTestSuiteRunner and override setup_databases and teardown_databases methods to pass.
Create a new settings file and set TEST_RUNNER to the new class you just created. Then when you’re running your test, specify your new settings file with –settings flag.
Here is what I did:
Create a custom test suit runner similar to this:
Create a custom settings:
When you’re running your tests, run it like the following with –settings flag set to your new settings file:
UPDATE: April/2018
Since Django 1.8, the module
django.test.simple.DjangoTestSuiteRunnerwere moved to'django.test.runner.DiscoverRunner'.For more info check official doc section about custom test runners.