[Answered ]-How to return multiple value from a pytest fixture with scope = session

1👍

You can invoke make_auto_login() in the fixture, this will execute the function and return api_client and user. After that in the tests auto_login_user will be a tuple with the values

conftest.py:

@pytest.fixture(scope="session")
@pytest.mark.django_db
def auto_login_user(api_client, create_user):
    def make_auto_login():
        print("_+==--=-=-=-===--=-=-==----=-=-=-=")
        user = create_user()
        api_client.login(username=user.username, password='strong-test-pass')
        return api_client, user
    return make_auto_login()

test_views.py

class TestViews:

    def test_generate_token_views_post(self, auto_login_user):
        api_client, user = auto_login_user
        assert True

    def test_generate_token_views_post2(self, auto_login_user):
        api_client, user = auto_login_user
        assert True
👤Guy

Leave a comment