-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Inconsistent behaviour of python3 -m pytest
and py.test
#911
Comments
The error is that I missed to put |
@sils1297 this is a artifact of the new style namespaces |
Perhaps you should raise a |
I am also seeing different behavior between @RonnyPfannschmidt is there any further reading on "new style namespaces"? |
@ssangervasi new style namespaces where introduced in python3 - there no longer is a can you perhaps show full output of the invocation another potential issue in your case is pythonpath vs imports in tests vs rootdirs which is unrelated to this issue |
@RonnyPfannschmidt thanks for the reply. You were correct and I now understand that my issue was unrelated. I was overlooking the fact that |
Py.test never does that unless there is a toplevel conftest, please give US more information |
Seeing the same problem, python3 -m pytest works and py.test doesn't for xonsh. it is a PYTHONPATH issue and the docs are very misleading in http://docs.pytest.org/en/latest/usage.html#cmdline: python -m pytest [...] no they are not, exactly because of pythonpath. Can we just do that on py.test? |
@DuncanBetts I'm not sure I follow, it seems the error is not really related to Either way I think updating the documentation would be a good first step as well. |
This should be documented in https://docs.pytest.org/en/latest/pythonpath.html |
Documentation added in #2850 |
I think we have added enough to the docs alerting to the difference between the two invocations so I'm closing this. |
Well, couldn't you make the behaviour of pytest match the behaviour of python -m pytest, as a "real" fix, or is that undesirable? |
@bilderbuchi that would be a real breaking change for a lit of people - so we cant just go ahead and do that |
I see. Still, is this something you want to do in the future, e.g. at next-major-version? If so, I guess it should be tracked. Personally, in the way I teach people to set up python projects (scientific scripts etc), I've resorted to just putting a section in the readme that says "try to run |
personally its not something im interested in (i just always use pytest) but feel free to open up a tracking issue and participate if its something you find helpful |
That is kinda my point, this issue is already the tracking issue for the behaviour in question (and should maybe be reopened), and I am participating. ;-) |
@bilderbuchi I sympathize with your problem, but I really think this is not something that we should do. Besides being backward incompatible and probably cause a lot of breakages, it would be undesirable to automatically add the current directory to |
OK, thank you. I understand. So, in case I want to have a simple project with some, say, data processing script or other one-off stuff that's not installed elsewhere, i.e. a layout like this:
what is best practice to make this work with a plain |
@bilderbuchi the suggestion agasint so in your case where you dont install and want to test the local code its perfectly fine, but perhaps worth a comment in the init.py to help understanding should it ever be turned into a installable package |
Great, thanks! |
Also: thank you for this great tool! 👏 |
In situations like this—where any change in behavior to fix one problem will probably create other problems, but where both situations are completely valid—I think the best thing to do is to issue a clear notification to the user about the situation, and inform them on how to adjust their invocation of pytest if necessary. From the pytest docs:
That is pretty clear in the docs. But ideally, pytest would detect when it is invoked via |
Good point. I'm not sure we can detect it though. |
Late to the party, but I strongly agree with not changing pytest to harmonize the The path-modified behavior of More-prominent advertising/education of the |
See http://pastebin.com/52ra33eN
Both commands show
but
py.test
isn't able to get the imports right.Steps to reproduce:
git clone https://github.com/coala-analyzer/PyPrint
git checkout pytestrep
(Auto sync with origin/pytestrep)py.test
/python3 -m pytest
in a python3 environmentThe text was updated successfully, but these errors were encountered: