Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flask Testing uses one request context per TestCase method #1444

Closed
psivesely opened this issue Nov 3, 2016 · 6 comments
Closed

Flask Testing uses one request context per TestCase method #1444

psivesely opened this issue Nov 3, 2016 · 6 comments

Comments

@psivesely
Copy link
Contributor

psivesely commented Nov 3, 2016

In normal usage, each request object is processed in it's own request context. In Flask Testing all request objects are processed in a single request context for a given TestCase method. If you're only making a single request in a test method, everything will work as expected. However, if you want to test anything more complicated (i.e., anything that involves multiple users or multiple requests from a single users), all bets are off. To illustrate the problem, I've uploaded a Gist that illustrates the problem with a very simple example, and a little further explanation in the comments: https://gist.github.com/nvesely/b6e72ae0902c97723fcf44b46160d499.

Edit: link surgery.

@psivesely
Copy link
Contributor Author

I started writing a subclass of flask_testing.TestCase that will reset the context before any request. That way the context will be preserved after a request (until the next one) in order to take advantage of the context assertion methods and other conveniences provided by Flask Testing, while still resolving this issue.

@psivesely
Copy link
Contributor Author

I made more progress on this over the weekend, but I totally screwed with my use of git and deleted that work in an unrecoverable manner 😭

@heartsucker
Copy link
Contributor

Would just like to point out that this is biting me in the ass right now and we should fix it. :(

@heartsucker
Copy link
Contributor

Pointing out that this one got me again while writing tests for session expiration.

heartsucker added a commit to heartsucker/securedrop that referenced this issue Oct 1, 2017
heartsucker added a commit to heartsucker/securedrop that referenced this issue Oct 1, 2017
heartsucker added a commit to heartsucker/securedrop that referenced this issue Oct 3, 2017
heartsucker added a commit to heartsucker/securedrop that referenced this issue Oct 5, 2017
heartsucker added a commit to heartsucker/securedrop that referenced this issue Oct 5, 2017
heartsucker added a commit to heartsucker/securedrop that referenced this issue Oct 5, 2017
@ghost ghost added the goals: more tests label Dec 4, 2017
@heartsucker
Copy link
Contributor

Pointing out that this is still a problem 😐 😐 😐

@legoktm
Copy link
Member

legoktm commented Sep 29, 2022

Use of flask-testing was removed in #2948 and finally in 65f092c.

@legoktm legoktm closed this as completed Sep 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants