webtest access to request object

17 views
Skip to first unread message

Gerhard Schmidt

unread,
Dec 8, 2021, 4:39:13 AM12/8/21
to pylons-discuss

Hi,

is there a way to access the pyramid request object webtest.TestApp.

especially in interested in the session. To test if information is stored.

Regards
Estartu
OpenPGP_0x3EE6A5DC78826E6B.asc
OpenPGP_signature

Nejc Zupan

unread,
Dec 8, 2021, 6:39:13 AM12/8/21
to pylons-...@googlegroups.com
I have the following in my conftest.py for exactly the purpose of inspecting the state of the request in tests.



class WebTestRequest(Request):
"""A custom WebTest request that allows access to Pyramid's Request."""

def __init__(
self,
environ: t.Dict,
charset: t.Optional[str] = None,
unicode_errors=None,
decode_param_names=None,
**kw
) -> None:
super(WebTestRequest, self).__init__(
environ, charset, unicode_errors, decode_param_names, **kw
)

# This allows us to get access to Pyramid request from WebTest
# response: resp.app_request
environ["paste.testing_variables"]["app_request"] = self


@pytest.fixture(scope="session")
def testapp(app: Router) -> WebTestApp:
"""Provide a webtest app for functional testing."""

app.request_factory = WebTestRequest
return WebTestApp(app)



Hope it helps,
z.
> --
> You received this message because you are subscribed to the Google Groups "pylons-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to pylons-discus...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/pylons-discuss/38dca48c-d116-6ded-0f03-3a25658e14bf%40augusta.de.
> <OpenPGP_0x3EE6A5DC78826E6B.asc>

Reply all
Reply to author
Forward
0 new messages