Below is an example of test code that uses a user
fixture to setup the test.
@pytest.fixture
def user():
# Setup db connection
yield User('test@example.com')
# Close db connection
def test_change_email(user):
new_email = 'new@example.com'
change_email(user, new_email)
assert user.email == new_email
Is there a way to generate multiple user objects in the same test using the same fixture, if I wanted to e.g. add functionality for changing user emails in bulk and needed 10 users setup before the test?