Better order tests when mixing transactional tests and Django test classes #830
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #827
test_db_order
to add Django test classes (test was failing, as expected)pytest_collection_modifyitems
to take Django classes into consideration (test is now passing)test_django_not_loaded_without_settings
About
test_django_not_loaded_without_settings
test_django_not_loaded_without_settings
is now failing. That's not a surprise since we importdjango
inplugin.py
. Moving the import in thepytest_collection_modifyitems
does not work either (since the function is run when collecting tests 🙃 )I tried looking for eg. a class attribute unique to
TestCase
orTransactionTestCase
but I didn't find any (not that it would be a great solution :)Another solution could be to dynamically import django in
pytest_collection_modifyitems
after checking forDJANGO_SETTINGS_MODULE
? Please advise if you have other / better ideas :)I ended up doing the dynamic import, taking inspiration from other places where
django_settings_is_configured
is used. It's a bit ugly but it does the job :O Improvements welcome :)