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
Look like if we will use scope session in fuxture that using multi db fixture will not work.
Example:
@pytest.fixture(scope='session')
@pytest.mark.django_db(databases=['default', 'other_db')
def create_unmanaged_db_models():
#Make some db action
...
@pytest.mark.usefixtures('create_unmanaged_db_models')
@pytest.mark.django_db(databases=['default', settings.LEADGEN_DB])
def test_some_case():
...
Will raise follow exception RuntimeError: Database access not allowed, use the "django_db" mark, or the "db" or "transactional_db" fixtures to enable it.
But if we will delete scope session code will work fine.
Example:
@pytest.fixture()
@pytest.mark.django_db(databases=['default', 'other_db')
def create_unmanaged_db_models():
#Make some db action
...
@pytest.mark.usefixtures('create_unmanaged_db_models')
@pytest.mark.django_db(databases=['default', settings.LEADGEN_DB])
def test_some_case():
...
Indeed, doing DB operations in the session scope (or really, any scope above function) is not supported. It is not related to multi-db, just a general constraint. The reason is that DB objects need to be created in the context of a test, so they could be cleaned up/rolled back at the end of it.
Look like if we will use scope session in fuxture that using multi db fixture will not work.
Example:
Will raise follow exception
RuntimeError: Database access not allowed, use the "django_db" mark, or the "db" or "transactional_db" fixtures to enable it.
But if we will delete scope session code will work fine.
Example:
Package versions:
pytest-django==4.3.0
Django==3.2.3
The text was updated successfully, but these errors were encountered: