-
-
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
"Import file mismatch" at test collection time #12123
Comments
Hi @lelit, thanks for the report. I could not reproduce the issue however, here is my file tree:
(all files are empty) This runs pytest file for me (with zero collected tests of course). Can you try to provide a minimal working example? |
Oh! I will try to distill an MWE, but for now a relatively quick (it takes a couple of minutes in total) recipe is:
The above works ok, producing
Then if I do
I get the following instead:
As said, I will try to minimize it. In the meantime, thanks for your time! |
Thanks! Same here: https://github.com/xflr6/graphviz/actions/runs/8317341967 (with multiple |
If that's any help, I was able to workaround the problem by specifying |
Hi, a little update: as promised I tried to come up with an MWE that exhibits the problem, but so far I had no luck in isolating the condition that triggers it. In another, even bigger project I wrote and maintain it does not happen, and neither in a very simplicistic mock, similar to what @nicoddemus did above, but with not completely empty files (test units and conftest.py). |
I suspect |
Thanks, I will take that into consideration, even if the other project I mentioned uses doctests as well but does not manifest the problem. |
Version 0.20.3 -------------- Revert improvements to the internal ``tools.deprecate_positional_args()`` decorator that caused false positive ``PendingDeprecationWarning: The signature of ... will be reduced`` warnings that have been misinterpreted in the 0.20.2 release process. Version 0.20.2 -------------- Drop Python 3.7 support (end of life 27 Jun 2023). Tag Python 3.11 and 3.12 support. Add caveat about ``labe`` escaping/quoting to ``.node()`` and ``.render()`` API docs. Document that ``doctest_skip_exe()`` lines in doctest should be ignored. Improve internal ``tools.deprecate_positional_args()`` decorator and fix incorect test assertion. Update GitHub actions. Pin ``pytest`` test dependency to ``<8.1`` as a workaround for ``import file mismatch error`` related to ``conftest.py`` files, in ``pytest 8.1.1``, see pytest-dev/pytest#12123.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
To avoid confusion, see e.g. #12123 (comment)
To avoid confusion, see e.g. #12123 (comment) Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
I'm sorry, I could not reserve some spare time to further investigate the issue, trying to condense a standalone replication recipe. |
To avoid confusion, see e.g. pytest-dev#12123 (comment) Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
To avoid confusion, see e.g. pytest-dev#12123 (comment) Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
While I was not able to distill a repeatable MWE recipe, I executed a git bisect start
git bisect bad 8.2.0
git bisect good 8.0.2
git run sh run.sh where pip install -U .
cd ~/wip/sol5/
pytest --collect-only The final outcome is the following:
Hope this brings some enlightenment. |
That didn't work, or wasn't noticed? |
FWIW, the issue is still present in v8.3.1, I'm a bit surprised nobody else is experiencing it, and no hint come up here. |
Hi @lelit thanks for checking. I am short on time myself to look into this more deeply however... some things to try meanwhile:
|
Thank you! |
Another thing to look for is if there are symlinks in the repo, or if some file imports conftest files explicitly. |
I believe adding |
Not in the Python sources, there is a single one between
No,
YES! This find tests -type d | grep -v __pycache__ | while read d; do touch $d/__init__.py; done made a difference indeed: at first the errors bumped to six, all of them like the following:
At that point the following patch --- a/tests/bio/test_serialization_gzip.py
+++ b/tests/bio/test_serialization_gzip.py
@@ -6,7 +6,7 @@
# :Copyright: © 2018 Lele Gaifax
#
-from test_serialization import full_dump_reload
+from .test_serialization import full_dump_reload
def test_full_dump_reload_gzip(session, tourney_rated, player_fata, player_lele): on those tests made 💌 |
Ahh great news, glad the problem was found @lelit! I'm closing this then. I wonder if we can improve pytest somehow to detect this problem, to at least give a warning? |
TL;DR: RonnyPfannschmidt's solution works for me I had the same issues and tried the same things as others in the thread:
This is what worked (from above):
I'm on Python 3.10 with the following
|
I tried to upgrade pytest from 8.0.2 to latest 8.1.1 and I got this error:
Neither removing all
__pycache__
subdirs, nor playing with the--import-mode
option fixed it.The top level
tests
directory contains this structure:and there are different
conftest.py
modules:Given that I could not find a related breaking change alert, I'd say that the "use a unique basename for your test file modules" hint does not apply to
conftest.py
, right?Thanks&bye.
Environment
I'm using Python 3.11.8 on a Debian
sid
, with the following packages in the virtual environment (after downgradingpytest
to the working8.0.2
):The text was updated successfully, but these errors were encountered: