-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Command line parsing fails when path is a value for an option #906
Comments
can you please show your folder layout as well including where you run py.test |
Running Python and Py.test in a virtualenv
I run py.test from at |
The problem is how
So pytest starts and loads the initial plugins (registered using setuptools) and To fix this I suggest the following options:
Having said all that, I think we should add something to the docs about this issue, as I believe it is a common source of confusion. |
I am not convinced your explanation is the reason why this fail. If I reverse the options to |
Hmmm sorry, I missed your note at the end:
So, if you execute:
You get:
But if you execute:
or
It works? |
That is correct. |
Thanks, sorry I misunderstood the problem initially. This certainly looks like a bug, thanks for the report! |
@Dude-x I'm having trouble obtaining the same error using the |
It seems issue #949 is somewhat related. I'll whip up a minimum viable test case later. |
Thanks! |
Here's a simple test case, using the latest stable release of py.test (2.7.2)
Content of conftest.py import pytest
def pytest_addoption(parser):
parser.addoption('--host', action='store', help='Host')
parser.addoption('--base_url', action='store', help='base URL')
def pytest_configure(config):
if config.getoption('host'):
print 'Host: {0}'.format(config.getoption('host'))
if config.getoption('base_url'):
print 'Base URL: {0}'.format(config.getoption('base_url')) Command line at /Users/dude-x/development/test-case
Output:
The thing to notice is that the rootdir is wrong, it should be /test-case, and not my parent. Here's one where it fails to parse:
|
Hi @Dude-x, thanks for posting the example. 😄 I think I know what's going on. During initialization, pytest tries to parse the arguments from the command-line. At this stage only builtin and plugin options are known, so the unknown args are kept aside for later inspection. After this, it tries to determine the So, it all boils down to the fact that conftests are loaded at a later stage than builtin and plugin options, which can affect which command line options will actually be validated and used as this mechanism depends entirely from where you execute If you change your conftest file into a plugin, it should work consistently no matter where you call It is unfortunate (but understandable) that there's this gotcha when working with |
I went to update
I will add a warning to not use that from |
On 27 Aug 2015 23:09, "Bruno Oliveira" notifications@github.com wrote:
That's a bit general, no? Using it in the top-level contest.py is generally |
I had trouble with this until recently at work, because we had a top-level |
Seems the aforementioned docs has moved |
I'm seeing this issue with pytest ≥ 2.8.0 with a plugin (not a conftest.py). The plugin I'm using is pytest-variables, but pytest-html is also affected. The argument values appear to be used for determining the root directory. |
On Mac OS X 10.10.4 using the latest homebrew Python 2.7.10, and py.test 2.7.2, if type on the command line:
py.test --app ~/path/to/app --host http://localhost:4444 tests/mobile
I get the following error:
This seems to be an issue regardless of OS or Python version.
This only works if I put the path as a last option. But this defeats the purpose of having options that can be set in "any" order.
This is a section of my conftest.py:
Things to note: A full path name works okay, but it seems that a ~ and a $varialbe will fail to parse.
The text was updated successfully, but these errors were encountered: