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

--reuse-db and --create-db not working together #411

Closed
ryankask opened this issue Oct 27, 2016 · 5 comments
Closed

--reuse-db and --create-db not working together #411

ryankask opened this issue Oct 27, 2016 · 5 comments

Comments

@ryankask
Copy link

ryankask commented Oct 27, 2016

I noticed the below issue when using the workflow presented here: https://pytest-django.readthedocs.io/en/latest/database.html#example-work-flow-with-reuse-db-and-create-db. It seems like the behaviour changed in a recent version although it's possible I never noticed this occurred.

When I run the tests passing the --create-db flag, the database is recreated and the migrations are run (notice the time). The database, however, is dropped despite the --reuse-db flag being passed via addopts.

$ pytest tests/app --create-db
...............................................................................................................................
127 passed in 8.23 seconds

When I next run the tests without the --create-db flag the database is again recreated and the migrations are run because it was previously dropped.

$ pytest tests/app
...............................................................................................................................
127 passed in 7.01 seconds

If I run the tests a third time exactly as above, the database is properly reused:

$ pytest tests/app
...............................................................................................................................
127 passed in 1.12 seconds
@ryankask
Copy link
Author

I've had a look at the code and can see a slight logic change in a recent refactor (#362) causes this.

The logic in django_db_setup used to be:

if not request.config.getvalue('reuse_db'):
        request.addfinalizer(teardown_database)

Now it is:

if not django_db_keepdb:
        request.addfinalizer(teardown_database)

where the django_db_keepdb fixture is request.config.getvalue('reuse_db') and not request.config.getvalue('create_db').

It's not a huge deal but it makes the docs here not incorrect but a bit misleading since the database is created twice.

@pelme
Copy link
Member

pelme commented Nov 13, 2016

Thanks for tracking it down! We should fix this and bring back the old behavior for sure.

@rinatio
Copy link

rinatio commented Jul 19, 2017

@pelme Could you please merge pull request from @dekkers ? Seems like it fixes this issue.

@rinatio
Copy link

rinatio commented Jul 19, 2017

Sorry, it is not a pull request. The fix still seems to be valid.

@blueyed
Copy link
Contributor

blueyed commented Jul 20, 2017

The PR is here: #476

ryan-shaw added a commit to SpatialBuzz/pytest-django that referenced this issue Dec 12, 2017
ryan-shaw added a commit to SpatialBuzz/pytest-django that referenced this issue Dec 12, 2017
ryan-shaw added a commit to SpatialBuzz/pytest-django that referenced this issue Dec 12, 2017
ryan-shaw added a commit to SpatialBuzz/pytest-django that referenced this issue Dec 12, 2017
ryan-shaw added a commit to SpatialBuzz/pytest-django that referenced this issue Feb 14, 2018
timb07 pushed a commit to timb07/pytest-django that referenced this issue May 26, 2018
beyondgeeks added a commit to beyondgeeks/django-pytest that referenced this issue Sep 6, 2022
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

Successfully merging a pull request may close this issue.

4 participants