Skip to content

WebTest argument relative_to shall assume current directory #163

Open

Description

@vlcinsky

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 ".")

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions