Closed jmccreight closed 4 years ago
I'm on mobile, but this looks like a classical case of non top level contest not partaking in cli parser configuration
The solution to this suspected case would be to have a top level contest or a entry point based plugin
Hi @jmccreight,
@RonnyPfannschmidt is correct.
Here is what happens when the user executes pytest --the-arg /
:
["--the-arg", "/"]
, so it parses:
--the-arg
as <unknown option "--the-arg">
/
as a <collection path "/">
conftest.py
files located either at the CWD (if no collection path(s) is given in the command-line), or at the paths given in the command-line. Here pytest assumes you meant to start collection from /
./
, but it does not see any conftest
files there, so the "initial conftest" collection stage ends. At this stage, if it had found conftest
files, they would be processed, but none have been found so nothing happens.conftest
from CWD was not yet been processed, so --the-flag
is not yet registered, so it errors out with an unknown flag.But when the user executes pytest --the-arg=/
:
<unknown option "--the-arg=/">
.<collection path>
was given, it starts collecting from CWD.conftest.py
file is found as an "initial conftest", so it is processed and --the-arg
gets registered.--the-arg=/
.The problem is that we can't know if a "path" lead by an unknown option will be consumed by it or not: the unknown option might have been just as well an option that does not consume the next argument, for example --enable
. For example, in this command-line:
$ pytest --enable /
Probably means that --enable
is a bool
option and pytest should collect from /
, but we can't really know that before hand.
There was an issue related to this but it was "closed". I dont see that the issue actually resolved. Even if this is a duplicate, I've found it extremely difficult to find any other matching issues here or elsewhere.... so it think it's worth repeating.
Pytest arugment parsing fails on the first absolute path argument when an
=
is not used. I assume the rules for failure are some how tied torootdir
identification because its then appears to be using the argument as root dir and coming up with the wrong conftest.py. Here's the simplest example:pip list
from the virtual environment you are usingFor pytest, see both above.