简体   繁体   中英

How to make Django unit-tests all retrieve from the same test database?

Currently when I run a set of unit-tests on Django, each test makes its own database. This means that traversing multiple features of the site all require a user sign up, login, etc.. It would be much simpler if they all fetched from the same temporary database - anyway to do this?

This is the default behavior of Django's transactional test case to perform a rollback after each test.

There is nothing preventing you, though, to have a module function, test case method or to override TestCase.setUp() to dynamically create test data. In fact, whenever you find yourself duplicating code, like creating the user and signing in with his credentials with the test client, you should find a way to make those bits reusable across your project's test cases.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM