-
-
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
Do not import duplicated modules with --importmode=importlib #12074
Do not import duplicated modules with --importmode=importlib #12074
Conversation
Regression brought up by pytest-dev#11475.
@flying-sheep I could not reproduce the issue using your reproducer, in
Perhaps this is due to me running Windows? Can you try this branch yourself perhaps? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regardless of whether it fixes @flying-sheep's issue, the change LGTM
Ah, sorry, the reproducer didn’t do what I thought it did. This one works. I’ll check if this PR fixes things: git clone https://github.com/scverse/anndata.git -b src2
cd anndata
python -m venv .venv
.venv/bin/pip install .[test] pytest@https://github.com/pytest-dev/pytest/releases/download/8.1.0/pytest-8.1.0-py3-none-any.whl
.venv/bin/pytest anndata src/anndata/tests/test_awkward.py::test_view src/anndata/tests/test_backed_sparse.py::test_empty_backed_indexing FAILED src/anndata/tests/test_awkward.py::test_view[obsm] - Failed: DID NOT WARN. No warnings of type (<class 'anndata._warnings.ImplicitModificationWarning'>,) were emitted.
FAILED src/anndata/tests/test_awkward.py::test_view[varm] - Failed: DID NOT WARN. No warnings of type (<class 'anndata._warnings.ImplicitModificationWarning'>,) were emitted.
ERROR src/anndata/tests/test_backed_sparse.py::test_empty_backed_indexing[zarr-empty_list] - ImportError: cannot import name 'write_zarr' from 'anndata._io.zarr' (/home/phil/Dev/Python/_reproducers/anndata/.venv/lib/python3.11/site-packages/zarr/__init__.py)
ERROR src/anndata/tests/test_backed_sparse.py::test_empty_backed_indexing[zarr-empty_bool_mask] - ImportError: cannot import name 'write_zarr' from 'anndata._io.zarr' (/home/phil/Dev/Python/_reproducers/anndata/.venv/lib/python3.11/site-packages/zarr/__init__.py) |
OK, I tried git clone https://github.com/scverse/anndata.git -b src2
cd anndata
python -m venv .venv
.venv/bin/pip install .[test] 'pytest@git+https://github.com/nicoddemus/pytest.git@11475-duplicated-imports'
.venv/bin/pytest anndata src/anndata/tests/test_awkward.py::test_view src/anndata/tests/test_backed_sparse.py::test_empty_backed_indexing and it worked! /edit: running all tests via 🥳 |
Awesome, thanks @flying-sheep! |
I think this may have introduced a different regression. Consider the following project structure with two packages under the
In
|
Just a little bit of a follow up, because I realize that my original comment wasn't the most clear. Below are the contents of
|
@aaraney thanks for the report, but could you open a new issue please (you can refer to this one there)? I will take a look at it ASAP. 👍 |
@nicoddemus, for sure! Thanks for taking a look at this! |
…dev#12074) Regression brought up by pytest-dev#11475.
This appears to have broken assertion re-writing with editable installs. |
This is fixed by #12313 |
@@ -539,6 +539,10 @@ def import_path( | |||
except CouldNotResolvePathError: | |||
pass | |||
else: | |||
# If the given module name is already in sys.modules, do not import it again. | |||
with contextlib.suppress(KeyError): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just taking a look again, i believe this should trigger a import mismatch if the file of the loaded module and the current path are different
Regression brought up by #11475.