pytest-flask-sqlalchemy icon indicating copy to clipboard operation
pytest-flask-sqlalchemy copied to clipboard

Is pytest-flask-sqlalchemy working with module scoped fixtures?

Open PashaKopka opened this issue 2 years ago • 1 comments

I want to use pytest-flask-sqlalchemy with fixtures with scope='module'

For example i have creating user:

@pytest.fixture(scope='module')
def user(db_session):
	user = User(
		username='My user',
	)
	db_session.add(user)
	db_session.commit()
	return user

Then when i testing some functions, after changing user, i get Instance not bound to session exception Example of changing user fixture:

@pytest.fixture
def user_with_other_username(db_session, user):
	user.username='Other username'
	db_session.add(user)
	db_session.commit()
	return user

I got this exception when user fixture has module scope. When i set function scope i hasn`t exception

PashaKopka avatar Jun 02 '22 09:06 PashaKopka

All the fixtures are function-scoped, therefore I don't think it's possible to use them at the module level

stabacco avatar Nov 20 '22 22:11 stabacco