Search code examples
pythondjangotestingmulti-database

Django, Tests and multidatabases


I have started to write tests to my django project. However I have question how to solve one problem. As my project has many databases and in my functions I have lines like

dbs = DataBaseSettings.objects.using("companies_db").all()

thanks to that I am retrieving data from chosen database. As we know, while testing django is creating new databases with prefix test_. So in this case do I have to refactor my whole code and get rid of such lines? Or maybe while testing django automatically creates route from "companies_db" to "test_companies_db"?


Solution

  • After a couple tests I found out that the test_companies_db is alias of companies_db. So everything works good.