pytest-django icon indicating copy to clipboard operation
pytest-django copied to clipboard

Order of settings and transactional_db fixtures

Open bdauvergne opened this issue 4 years ago • 2 comments

I use both in my tests and I created a media fixture (creating a temporary media directory and using the settings fixture) with autouse=True, due to alphabetic order it made the settings fixture run before the transactional_db fixture, but my post_migrate handler creating basic models depend upon the settings, in a test testing modification of those settings the teardown of transactional_db calling the flush() run with the modified settings instead of the default settings, modifying the default state of the database.

I think that a way of forcing run of setting before transactional_db must be found, as the post_migrate handler can depend upon the settings.

bdauvergne avatar Sep 24 '20 09:09 bdauvergne

I tried to follow what you are saying but the paragraph is a bit long and hard to understand. Can you rephrase it such that a simpleton like me can understand? :smile: The deputy likes dots!

bluetech avatar Apr 10 '21 17:04 bluetech

Simplification would be all pytest-django Django fixtures can depend upon the settings in a way or another but the ordering between the settings fixtures and other fixtures is mainly random. It would be useful that this order is fixed and documented. You can ignore my particular solution in the pull request, it just illustrates the problem. Note that it is a fundamental problem with the way pytest fixtures works, I think that without explicit dependencies between fixtures their ordering depend on their name or point of definition, I don't remember exactly. There is no way to indicate such fixture must run around another without depending on it.

bdauvergne avatar Apr 11 '21 09:04 bdauvergne