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

WebTest argument relative_to shall assume current directory #163

Open
vlcinsky opened this issue Jul 25, 2016 · 0 comments
Open

WebTest argument relative_to shall assume current directory #163

vlcinsky opened this issue Jul 25, 2016 · 0 comments

Comments

@vlcinsky
Copy link

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:

  • instance of WSGI application
  • url of web application to use via WsgiProxy2
  • reference to Paste config section, e.g. config:local.ini#test or config:local.ini (value being the same as when used as pserve command line argument.

Failures when using reference to config file

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 ".")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant