Pylons / Pylons/webtest

`WebTest` argument `relative_to` shall assume current directory

Open
#163 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
346
Forks
113
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at WebTest.init and the shown loadapp(app, relative_to=relative_to) call. Check how config references are loaded when relative_to is None, then verify that TestApp(app) works for config references while explicit relative_to values continue to work.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing-qa
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.