Pylons / webtest

Wraps any WSGI application and makes it easy to send test requests to that application, without starting up an HTTP server.
https://docs.pylonsproject.org/projects/webtest/en/latest/
Other
336 stars 110 forks source link

`WebTest` argument `relative_to` shall assume current directory #163

Open vlcinsky opened 8 years ago

vlcinsky commented 8 years ago

WebTest works well with WSGI applications as well as urls provided via environment variable WEBTEST_TARGET_URL.

WebTest.__init__ provides argument relative_to with default value None.

Typical creation of TestApp instance is:

from webtest import TestApp
# somehow create `app`, can be WSGI application or url to use
...

testapp = TestApp(app)

There are multiple options for providing argument app:

When using the reference to config file (either as direct value or indirectly via environment variable WEBTEST_TARGET_URL), the instantiation fails at http://webtest.pythonpaste.org/en/latest/api.html#webtest.app.TestApp as the relative_to is None.

Quick fix is to

testapp = TestApp(app, relative_to=".")

which in most cases works as expected, however it seems inconsistent with all other calls as one has to provide extra argument just in case, someone would be willing to define app via a reference to config file.

Proposed resolution

Keep default value of relative_to as None, but if to be used (before the call to loadapp, check if it is None and if so, set it to ".".

Existing line:

app = loadapp(app, relative_to=relative_to)

could change to:

app = loadapp(app, relative_to=relative_to or ".")