-
Notifications
You must be signed in to change notification settings - Fork 224
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
Avoiding source-tree imports during CIBW_TEST_COMMAND #1534
Comments
off the top of my head, could we
I'll keep pondering this. Ideas welcome. |
As this in part spawned from the discussion I started, I wanted to note that the solution of using import mode |
That's why they haven't activated importlib by default - it's too different from the old hacks. In general, you should not assume your test directory is importable, and use pytest 7's new IMO, support for non-src directory layout is a Python and pytest bug, and not ours. Even if cibuildwheel "fixes" this, it's still broken outside of cibuildwheel, so there still will be hidden landmines for users. I'm not really even a big fan of changing the path we do, and once Python <3.11 support is dropped, I could see recommending we set Here's a report today about a similar issue that has nothing to do with cibuildwheel: scikit-build/scikit-build-core#406 I don't think we should try to dig ourselves even deeper in trying to fix buggy package design by assuming people are using pytest and muddling with pytest settings. I think we could document that adding |
Yeah... on reflection these seem too hacky to be useful. I'm now thinking that instead we add a note to the test-command docs, to the effect:
At this point i'm a little stuck - actually
What did you mean by the 'adding |
I'd add as a recommendation you don't use "test" as the name for your test folder, but always "tests". Solves that problem. :) This would be the structure for test utils:
No pythonpath = ["tests/utils"] Then inside your test code you import The downside to this is it's not great for IDE's, but they have a setting (VSCode does, anyway) to add extra folders to a project's path, they just don't pick up on this one. Adding |
(Since I always use src layout and |
Have you tried |
Continuing from #1530 (reply in thread)
It seems that pytest defaults to 'prepend' import mode, meaning that for a source tree without a
/src
folder, like thismymodule
__init__.py
main.py
extension.c
tests
test_main.py
Even when invoked as cibuildwheel does, with the wheel installed in a venv, with cwd as a random temp dir, the
mymodule
folder in the source tree is higher in the import order than the installed wheel.This is a pity, the intention of changing the cwd during the
test-command
was to prevent this problem. I'm trying to think if there's a way that cibuildwheel can work around this...? Obviously the/src
structure is best, but we can't mandate that for all cibuildwheel projects.Another thing that I do wonder is if it's even worth changing the cwd for the
test-command
given this pytest default - it's a common gotcha within cibuildwheel, and if the above is universally true it's not even helping...!The text was updated successfully, but these errors were encountered: