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

Lock/unlock of db breaks if pytest is executed twice in the same process (fixes #1147) #1148

Merged
merged 2 commits into from
Sep 28, 2024

Conversation

boxed
Copy link
Contributor

@boxed boxed commented Sep 26, 2024

No description provided.

Copy link
Member

@bluetech bluetech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the patch, I can see the problem this is fixing.

I would prefer another fix. The problem occurs because, in order to block DB access by default, pytest-django runs an initial block() in _setup_django(), but doesn't restore it at the end, so it sticks around. The correct fix IMO is to add a restore to balance the _setup_django one, probably in a pytest_unconfigure hook. DjangoDbBlocker by itself is good.

Would you mind trying it?

@boxed
Copy link
Contributor Author

boxed commented Sep 28, 2024

Hmm. Yea that seems better. Although there is something iffy with the code as it is now, because the setting of the original ensure connection function isn't guaranteed to set the original function every time. Maybe an assert that the __module__ of the function is what we expect might be nice too?

@boxed
Copy link
Contributor Author

boxed commented Sep 28, 2024

This change works on my test project and I think this is what you meant in your comment above.

Copy link
Member

@bluetech bluetech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@bluetech bluetech merged commit 259fb85 into pytest-dev:main Sep 28, 2024
17 checks passed
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.

2 participants