-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Command-line arguments that are files which exist cause conftest.py not to be loaded from the usual location #436
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
Comments
Original comment by Marc Abramowitz (BitBucket: msabramo, GitHub: msabramo): Ah, I just discovered that it's not unique to
So my theory is that when py.test sees a file on the command-line and it exists, it treats it something like a test and then expects the This is bolstered by the fact that if the resultlog file is in the same directory as
|
Original comment by Marc Abramowitz (BitBucket: msabramo, GitHub: msabramo): OK, I created a PR with a possible way to address this: https://bitbucket.org/hpk42/pytest/pull-request/116/fix-for-issue-436-add-heuristics-to-ignore/diff I feel like an even better solution is to discover conftest.py files while doing test discovery. I am guessing that this doesn't happen now because it looks for conftest.py files very early in the process before even command-line arguments are parsed (because it can add options, change discovery, etc. presumably). But maybe it can continue to do this and do another pass looking for conftest.py files in the test discovery phase? |
Original comment by Marc Abramowitz (BitBucket: msabramo, GitHub: msabramo): I have another approach for solving this at: https://bitbucket.org/hpk42/pytest/pull-request/117/fix-issue-436-2-by-looking-for-tests-dirs/diff |
Original comment by holger krekel (BitBucket: hpk42, GitHub: hpk42): A few things:
One of the reasons for the heuristics is to allow running pytest like this: Maybe implementing #430 might help in combination with looking for paths that look like they are pointing somewhere else ( We can give up on the ability of specifying Note that for this issue, implementing #430 and specifying I tend to think it's better to introduce fully predictable behaviour rather than trying to enhance the heuristics. Might break some people's test invocation scripts or tox.ini's so maybe better a change for 2.6? |
Original comment by Marc Abramowitz (BitBucket: msabramo, GitHub: msabramo): @hpk42: Thanks for the detailed explanation!
Ah, I didn't know this, but now that I do, that made me think of another possible way to address the problem... What if when py.test detects an "anchor" file on the command-line, it outputs a warning along the lines of: "Found file argument 'junit.xml' in the command-line arguments, preceded by the argument '--junitxml'. Going to look for conftest.py files relative to the directory containing 'junit.xml'. If you don't want this to occur, then you may want to specify '--junitxml=junit.xml' (note equal sign between arguments) instead of '--junitxml junit.xml' (note space between arguments)." At least that way, folks know what is happening (it's not obvious right now) and you give them a chance to change their habits in a way that prevents problems. Maybe that warning will be annoying when people specify paths like "../" and what not. But maybe it's worth it, I don't know. It also occurs to me that in any legitimate case I can think of where one would use "../" or whatever to point py.test to tests in another directory, the argument would seem to always have a slash in it. Well, maybe except for "." and "..". But generally specifying a file in the current directory like "junit.xml" or "result.log" would be a strange thing to do. Would it always be either a directory or a .py file if someone was trying to get py.tests to run tests somewhere else? Another possible way to address this is to change the interface (so for 2.6) so that the user cannot specify a path by itself to get py.test to run tests there. Instead they would have to supply an explicit option -- e.g.: |
Original comment by Marc Abramowitz (BitBucket: msabramo, GitHub: msabramo): A stab at a warning: $ hg diff
diff --git a/_pytest/config.py b/_pytest/config.py
--- a/_pytest/config.py
+++ b/_pytest/config.py
@@ -484,6 +484,14 @@
continue
anchor = current.join(arg, abs=1)
if exists(anchor): # we found some file object
+ sys.stderr.write("-" * 78 + "\n")
+ sys.stderr.write(
+ "Found file in args: %r; Looking for conftest.py\n"
+ "relative to that file...\n" % arg)
+ sys.stderr.write(
+ "If this file was a value for a previous argument, you\n"
+ "might want to separate it with an = rather than a space.\n")
+ sys.stderr.write("-" * 78 + "\n")
self._try_load_conftest(anchor)
foundanchor = True
if not foundanchor: |
Original comment by Marc Abramowitz (BitBucket: msabramo, GitHub: msabramo): And here's another change that I think would be good to make -- make it so that the help shows the arguments with the equals sign instead of the space, since that is less prone to error: diff --git a/_pytest/config.py b/_pytest/config.py
--- a/_pytest/config.py
+++ b/_pytest/config.py
@@ -442,7 +442,7 @@
if len(option) == 2 or option[2] == ' ':
return_list.append(option)
if option[2:] == short_long.get(option.replace('-', '')):
- return_list.append(option)
+ return_list.append(option.replace(' ', '='))
action._formatted_action_invocation = ', '.join(return_list)
return action._formatted_action_invocation Looks like this: $ py.test -h | egrep '=path'
--junit-xml=path create junit-xml style report file at given path.
--result-log=path path for machine-readable result log.
--ignore=path ignore path during collection (multi-allowed).
--genscript=path create standalone pytest script at given target path. |
Original comment by holger krekel (BitBucket: hpk42, GitHub: hpk42): This got lost a bit (along with the PRs) due to my vacation. On the plus side i took a fresh look and think we could at least cover your original cases by only considering Modifying the help to show "=" is ok i think, helps to reduce the principle problem. I also agree with adding a warning (could be done by "config.warn" on trunk) but it should only be given if after the actual command line parsing took place and either failed and would provide a different anchor. As it stands, don't want to otherwise further the heuristics and rather go for #430. Therefore i am bound to decline your Pull Request #116 and 117 but would be very happy for a new one implementing the above suggestions (also only one of them to get started). |
Original comment by holger krekel (BitBucket: hpk42, GitHub: hpk42): fix issue436: improved finding of initial conftest files from command |
Originally reported by: Marc Abramowitz (BitBucket: msabramo, GitHub: msabramo)
Maybe or maybe not related to https://bitbucket.org/hpk42/pytest/issue/416/option-added-in-conftestpy-not-available, which uses a very similar example ("runslow) in fact.
Now...
The first time that I run
py.test
with--junitxml junit.xml
and-k test_stuff
and there is nojunit.xml
file yet, it works fine:Now that
junit.xml
exists:A second invocation fails:
If I remove
--junitxml junit.xml
, it doesn't exhibit the problem:It also goes away if I specify the
tests/
directory:I can't figure out what is going on here...
The text was updated successfully, but these errors were encountered: