Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid creating test database for testing in django?

I have written some test cases for my project when I run these test cases, it creates test database for alias 'default' every time, after giving message then destroy database. I am concern only with message, So How to avoid creating test database, because it takes lots of time.

username$ ./manage.py test
...............
Some message, I Want only this message 
...............
Creating test database for alias 'default'...
----------------------------------------------------------------------
Ran 0 tests in 0.000s

OK
Destroying test database for alias 'default'...
like image 666
geeks Avatar asked Sep 18 '15 05:09

geeks


People also ask

How do I skip a Django test?

Just trick it to always skip with the argument True : @skipIf(True, "I don't want to run this test yet") def test_something(): ... If you are looking to simply not run certain test files, the best way is probably to use fab or other tool and run particular tests.

What database does Django test use?

To help you get started, Django provides and uses a sample settings module that uses the SQLite database. See Using another settings module to learn how to use a different settings module to run the tests with a different database.

Where does Django store test database?

from the docs: When using SQLite, the tests will use an in-memory database by default (i.e., the database will be created in memory, bypassing the filesystem entirely!).

Can database be mocked for unit testing?

Yes, absolutely! Because our code that talks to the real DB is already tested carefully in the previous lecture. So all we need to do is: make sure that the mock DB implements the same interface as the real DB. Then everything will be working just fine when being put together.


1 Answers

Well, it's just a comment, not an answer yet - so I'll repeat the comment of Rahul Gupta:

Just subclass from SimpleTestCase instead of TestCase, see Django Testing Tools Documentation.

like image 123
OBu Avatar answered Oct 07 '22 01:10

OBu