Skip to content

Better order tests when mixing transactional tests and Django test classes #830

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

Merged
merged 2 commits into from
Mar 20, 2020

Conversation

pmourlanne
Copy link
Contributor

@pmourlanne pmourlanne commented Mar 19, 2020

Closes #827

  • Edited test_db_order to add Django test classes (test was failing, as expected)
  • Changed pytest_collection_modifyitems to take Django classes into consideration (test is now passing)
  • Fix 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 import django in plugin.py. Moving the import in the pytest_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 or TransactionTestCase 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 for DJANGO_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 :)

@pmourlanne pmourlanne changed the title Ordering transactional unittest Better order tests when mixing transactional tests and Django test classes Mar 19, 2020
@pmourlanne pmourlanne force-pushed the ordering-transactional-unittest branch from e45fce8 to 775df6f Compare March 19, 2020 08:50
Copy link
Contributor

@blueyed blueyed left a comment

Choose a reason for hiding this comment

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

Nice, thanks!
Left some comments/ideas.

@pmourlanne pmourlanne force-pushed the ordering-transactional-unittest branch from 775df6f to d19ed96 Compare March 19, 2020 11:18
@pmourlanne
Copy link
Contributor Author

pmourlanne commented Mar 19, 2020

I should have taken your comments into account, tell me if you still see things to improve / change 🕵️‍♀️

Copy link
Contributor

@blueyed blueyed left a comment

Choose a reason for hiding this comment

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

Awesome, thanks!

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.

Unexpected test order when mixing pytest / unittest tests and transactional tests
2 participants