-
-
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
Support external tests, with __init__, WITHOUT forcing src/ layout #4714
Comments
based on timelines i expect to happen we can address this after pytest5.x which will be the last to support python2 this would also be a great chance to move our python import mechanism away from we still have to take a look at whether this can nicely integrate assertion rewriting |
Like I said, I'm pretty sure it is possible to do this on python 2 as well. (In particular, ...oh, doing a bit more grepping, I see that you're already messing with |
from my pov, im more than happy/willing to make this a python3 only feature but we do have to take into account nested varied import root situations |
Yeah, I actually have no idea how pytest's logic for test discovery and path management really works, I always just flail around until something useful happens. So I guess that's my biggest question here, whether this could be slotted into that logic without breaking everything. |
In this PR we relocate all source files -- both C++ and Python -- into the `/src` directory. The reason for why this setup is preferred is explained in https://blog.ionelmc.ro/2014/05/25/python-packaging; however for us such move is in fact a necessity: with our previous setup it was impossible for `pytest` to properly test datatable installed from a wheel. Although pytest may eventually fix this problem (pytest-dev/pytest#4714), for now the most reliable solution is to have the `datatable/` folder not in the root of the repository. As for the `c` folder, there was no good reason to move it, except that now that we have the `src/` folder it seems only logical that the C++ code should also live there. Also, I've inserted `sys.path.insert(0, "src")` in the tests/__init__.py and tests/conftest.py -- these are temporary changes, designed to ease the transition towards the new file layout.
This was implemented in #7246. |
In the pytest docs, it recommends against the following layout:
This is a very convenient layout, so it's unfortunate that it's not supported. The main problem is a technical one. As the docs say:
And this is bad because now you can't test against an installed version of
mypkg
.My proposal is: we should fix this technical issue. Pytest should be able to import the
tests
directory, without the side-effect of makingmypkg
automatically importable as well.On Python 3, this is actually trivial to implement. All you have to do is:
Now
import tests
, orimport tests.foo
, will find our tests in"/some/path"
, ignoringsys.path
. But,import mypkg
will continue to searchsys.path
as normal.It should be possible on python 2 as well, but I haven't yet stared at PEP 302 for long enough to figure out the details.
Anyway, the question is: given that this is technically possible (and pretty easy at that), is it viable to fix this in pytest, or are there other issues that would block that?
The text was updated successfully, but these errors were encountered: