You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I create the message instance in a fixture with scope='module', right in the test file. But when the test reaches another module, this message instance still exists in the database.
After I replaced the 'return' with a 'yield', and after the 'yield' I manually deleted the object, everything works correctly. But shouldn't the test do it automatically, as it does in my other fixtures? For example, if scope = 'function' then the test automatically deletes the object (after each test), without any 'yield'
If the message instance is not manually deleted, it will exist throughout the entire session, even if scope='module'. Why is this happening???
@pytest.fixture(scope='module')defmessage_by_auth_user(django_db_setup, django_db_blocker,
message_factory: type,
user_factory: type,
user_with_auth: User) ->Message:
"""Return message by auth user."""withdjango_db_blocker.unblock():
message=message_factory(written_by=user_with_auth)
yieldmessagemessage.delete() # This code is executed when fixture run teardown, after testing current module
why does function scope fixtures delete it automatically after each test? I expect module scope fixture to have the same behavior after each test module.
The text was updated successfully, but these errors were encountered:
Doing DB things in non function-scopes fixtures is currently not reset automatically by pytest-django. Unfortunately it is not so simple to achieve. There are several issues about this, e.g. #514, #105 so I'll close this one.
I create the message instance in a fixture with scope='module', right in the test file. But when the test reaches another module, this message instance still exists in the database.
in .../apps/dialogs/test/api/test_message.py
in .../apps/users/test/api/test_users.py
After I replaced the 'return' with a 'yield', and after the 'yield' I manually deleted the object, everything works correctly. But shouldn't the test do it automatically, as it does in my other fixtures? For example, if scope = 'function' then the test automatically deletes the object (after each test), without any 'yield'
If the message instance is not manually deleted, it will exist throughout the entire session, even if scope='module'. Why is this happening???
why does function scope fixtures delete it automatically after each test? I expect module scope fixture to have the same behavior after each test module.
The text was updated successfully, but these errors were encountered: