Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to re-use existing database even with REUSE_DB=1 #290

Open
lokeshatbigbasket opened this issue Nov 7, 2017 · 1 comment
Open

Comments

@lokeshatbigbasket
Copy link

I am unable to re-use existing DB when running tests, getting following errors:

nosetests order.tests.adminviews.test_tpl_reports:TestTPLReport REUSE_DB=1 --verbosity=1 Creating test database for alias 'default'... Got an error creating the test database: (1007, "Can't create database 'test_test_bigbasket'; database exists") Type 'yes' if you would like to try deleting the test database 'test_test_bigbasket', or 'no' to cancel: no Tests cancelled.

When I say no the tests are cancelled, it's not re-using the existing DB.

Our project is very large and here's it: https://pastebin.com/pSZwm9rB

@jwhitlock jwhitlock added this to the Fix REUSE_DB=1 milestone Nov 8, 2017
@crucialfelix
Copy link

You have to say "yes". It will then delete it, then recreate it, then delete it when it finishes the tests.

Then run another test. It will create it, but it won't delete it.

Now you can run tests with --keepdb and it will keep reusing that same one without deleting it.

REUSE_DB=1 ./manage.py test --keepdb

If you have to delete it (migrations won't run, you switched to an incompatible feature branch etc.) then omit --keepdb and it will offer to delete the old one.

This is what I use on my mac for running tests in docker:

#  ~/.bash_profile
quickTest () {
	docker-compose run --rm -e REUSE_DB=1 -e TESTING=True web python ./manage.py test --keepdb --parallel -v 2 "$@"
}
alias qt=quickTest

Usage:

qt 
qt appname
qt appname.tests.test_module

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants