In test_something(), the app instance should be the same as used by the login instance.
@pytest.fixture
def app():
# ...
return app
@pytest.fixture
def login(app):
# ...
return login
def test_something(self, app, login):
pass
What I tried is returning both objects from the second fixture, but I wouldn't call this idiomatic.
@pytest.fixture
def app_and_login(app):
# ...
return app, login
def test_something(self, app_and_login):
app, login = login_and_login
Is there a better way to do this?
As you described, the fixture already is shared for the runtime of the test by default.
This isn't really documented explicitly anywhere (or at least I haven't found it), but it's somewhat implicit: Sharing a fixture across tests in a module describes the scope parameter, and the default scope is function.
Other scopes would e.g. be module (share/cache the fixture for all tests in the same module) or session (cache the fixture for the whole test session).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With