Skip to content

Cookie changes are not persisted when test client follows redirects #1491

@javivdm

Description

@javivdm

I have a pytest test from a flask application that looks like:

def test_logout_redirect(client, login, credentials_admin):
    with client as c:
        login(c, credentials_admin)
        r = c.get(url_for('main.logout'), follow_redirects=True)
        assert r.status_code == 200
        assert request.path == url_for('main.login')
        assert b'Log In' in r.data

When the user logs out, the session is cleared and it redirects them to the login page. The log in route checks if the session has a user id, and if so it redirects them to the homepage.

Therefore the test is trying to assert that the session is cleared after logging out and the user is redirected to the login page. This test was passing in 0.14.1.

However after upgrading the test fails. It seems like the user ID is back in the session after it has been cleared and therefore the user ends up in the homepage.

I am encountering this behaviour only when using the test client, which I am invoking with flask's app.test_client().

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions