I know this question is old, but I'm not seeing the behavior you describe, and I got really sidetracked by this Q&A until I thought, "It can't work that way..." and tested it out for myself. I tried this on:
platform darwin -- Python 3.7.7, pytest-6.0.1, py-1.9.0, pluggy-0.13.1 -- .../bin/python3
I made this test, and it passes:
import collections
import pytest
AppObject = collections.namedtuple("App", ["name", "login"])
@pytest.fixture
def app():
app = AppObject("appname", "applogin")
return app
@pytest.fixture
def login(app):
return app.login
def test_something(app, login):
assert isinstance(app, AppObject) and app.name == "appname"
assert isinstance(login, str) and login == "applogin"
OP seems concerned about the app object being received by the login fixture being different from the app returned by the app fixture. I don't see that happening. For instance, if you add some helpful print statements like this:
import collections
import pytest
AppObject = collections.namedtuple("App", ["name", "login"])
@pytest.fixture
def app():
app = AppObject("appname", "applogin")
print("Object id in app fixture: %d" % id(app))
return app
@pytest.fixture
def login(app):
print("Object id in login fixture: %d" % id(app))
return app.login
def test_something(app, login):
print("Object id in test: %d" % id(app))
assert isinstance(app, AppObject) and app.name == "appname"
assert isinstance(login, str) and login == "applogin"
I see this output:
Object id in app fixture: 4451368624
Object id in login fixture: 4451368624
Object id in test: 4451368624
...so it's definitely the same object in all three places. Nested fixtures like this "just work" for me, so I'm either missing the point of the question you were asking, or behavior has changed, or... something else. But I wanted to leave this here for others who come along looking for nested/dependent fixtures like this.