Skip to content

[MINOR] add opt-in multi-database support for db fixtures #896

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

Conversation

averagechris
Copy link

@averagechris averagechris commented Dec 15, 2020

Adds opt-in multi-database support for database fixtures (db, transactional_db) to cleanup in databases other than default.

This approach uses a setting in settings.DATABASES["db_name"]["TEST"]["PYTEST_DJANGO_ALLOW_TRANSACTIONS"] to determine whether the database fixtures should create a transaction, or cleanup that database after each test. It does this by extending the collection of database names on the relevant django TestCase's databases attribute or by setting multi_db=True for compatibility with django version <=1.8.x.

TODO:

@bluetech
Copy link
Member

Hi @mistahchris,

I don't have much experience with non-replica mutli-db but I'll try to find time to research the issues and look into your PR. Any more details/considerations you can add would be useful.

In the meantime, I noticed you have some code for django versions <= 1.8.X. Current pytest-django only supports Django>=2.2 so you don't need to worry about <=1.8.

@averagechris
Copy link
Author

Hi @bluetech,

Thanks for taking the time to look into this PR! Let me know if I can help answer any questions. I've had to work with multiple databases quite a bit for work, which prompted me to make this PR in the first place.

I'll ditch the django 1.8.x stuff and fix the failing check on Monday or Tuesday this week (in next couple of days).

@aijorgenson
Copy link

This PR may also indirectly resolve #297

@averagechris
Copy link
Author

Sorry about ghosting on this PR. My computer died and I just got my new one a few days ago. I'm working on setting up my python environment today so I can make the tweaks to this PR this weekend.

@jgb
Copy link

jgb commented Apr 8, 2021

@mistahchris any update on this PR? Would love to try it out.

@bluetech
Copy link
Member

bluetech commented May 7, 2021

So I'm going over all of the multi-db issues and PRs, trying to understand the material.

The approach you've taken here is to have a global setting, which affects all of the tests. I think this is too coarse -- one should be able to configure the databases on a per-test way, for efficiency and control. This is what the underlying Django TestCase provides. This means it should be configured on the mark/fixture.

I'll close this PR then, but I'll open an issue discussing multi-db support and will cc this.

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 this pull request may close these issues.

4 participants