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
docs suggestion - TestApp context manager #3329
Comments
A generic implementation would belong in WebTest docs, whereas one specific for Pyramid would belong either in https://docs.pylonsproject.org/projects/pyramid/en/latest/narr/testing.html or https://docs.pylonsproject.org/projects/pyramid-cookbook/en/latest/testing/index.html. This use case seems rare to me, so I'm inclined to think it belongs in the Cookbook. |
I can generate some text for either, but it's the test-flow is not rare (while the use-case is). The same contextual cookie manager can be used for things like swapping out different users to ensure privacy permissions work. This actually let me migrate a lot of integrated tests that use |
This needs to be submitted as a well formed PR to either the pyramid docs or to the cookbook. I would suggest the cookbook because we're way less strict on what patterns we advocate there and this looks like it fits the purpose of the cookbook perfectly. With respect to the content itself, I can't see anything here that can't be accomplished by simply defining testapp1 and testapp2, each wrapping the app separately and maintaining their own cookiejars. |
@mmerickel that sounds like a great approach. i didn't realize TestApp was just a wrapper around a configured pyramid app. |
Writing some unittests for oAuth flows were a battle, because I needed a single instance of
webtest.TestApp(app)
that was used by two different consumers (client browser and client server), and TestApp stores it's cookies locally.I ended up solving this with a context manger to swap the cookiejar out for a bit. I wanted to offer this for the narrative docs (or perhaps webtest?) because it eliminated so many headaches in our testing.
Which is then used like the below, which will use a single testapp in which
res1
andres3
use the default cookies butres2
uses it's own set.The text was updated successfully, but these errors were encountered: