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
Access session object during unittest #18
Comments
I do not recommend triggering the request handling like this. The nicer solution is the test_client like the example tests do: http://github.com/mitsuhiko/flask/blob/master/examples/minitwit/minitwit_tests.py The big advantage is that it does not depend on a certain way to dispatch requests and tests will continue to work if one refactors the request dispatching. |
I assume that using test_client there is no way to access the session since test_client treats the app as a black box. That was what thadeusb was trying to do. |
That is indeed the case but you can hook in a temporary view so that you can access the session from there (for example). There are other ways as well but I'm not sure if its not a better idea to test the application as blackbox in general. |
I figured the purpose of unittesting was to make sure your application was working properly. What if I store a fairly large object in session (say I am making a ampache clone) and I store the playlist. I need to verify that that playlist is correct in the session object, I can't even look at it correctly from an html stand point. There is another issue with black-box testing, what if I change the way my flash messsage is worded? Well now all my tests are broken, even though my application works just fine and dandy. |
Added example for context bound objects to the testing docs. This closed by 8d49440 |
Can we get the docs updated to include an example to access session object while unit testing.
Here is a potential solution, using unittest for flaskr
The text was updated successfully, but these errors were encountered: