When performing database CRUD operations in a fixture in pytest, why is the scope limited to 'function'?

24 Views Asked by At
@pytest.fixture(scope='function')
@pytest.mark.django_db()
def authenticated_user_object(authenticated_user_data):
    user = get_user_model().objects.create_user(
        **authenticated_user_data
    )
    return user

After saving the user information in the DB as above with pytest, I tried to run the test by setting the scope to a level higher than the 'function' level to run several tests. However, I received a log message that DB access was not allowed, and while I was looking into it in detail, I was wondering why DB access was denied at the function level.

  1. Specifically, what is the reason for making DB access impossible in scopes beyond function?
  2. Are there other ways to access the DB?
0

There are 0 best solutions below