pytest-dev / pytest-dev/pytest-flask

Sessions are empty when testing

Open
#69 7 comments 10 reactions 1 assignee View on GitHub

@northernSage is already working on this.

Since Mar 31, 2021.

Dominant language
Python
Stars
499
Forks
93
PR merge metrics
No merged PRs in 30d

Description

This doc expresses that we can access session without any extra context manager.

However the following code does not return any session key (session is empty):

from flask import Flask


import pytest
from flask import session


myapp = Flask('testing')
myapp.secret_key = 'secret'
myapp.debug = True

@myapp.route('/')
def home():
    return session['message']


@pytest.fixture
def app():
    return myapp


def test_home(client):
    session['message'] = 'something'
    response = client.get('/')
    assert response.data == 'something'

Any hint on what we're missing here?

Thanks :)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.