Skip to content

Question regarding --import-mode=importlib #12714

Answered by nicoddemus
Kludex asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @Kludex finally found the time to investigate a bit more.

Actually pytest will use resolve_pkg_root_and_module_name to derive the full test module name, so it will derive the package root based on the presence of __init__.py files on the file's directory and upwards.

In your example, for /projects/jik/src/jik-app/tests/test_app.py, it finds /projects/jik/src/jik-app/tests as the package root, and then /projects/jik/src/jik-app/tests gets added as tests to sys.modules, which results in this clashing later when importing from src/uvicorn, as tests.utils will not refer to src/uvicorn/tests/utils.py, but to src/jik-app/tests/utils.py (which does not exist) due to tests already being a modu…

Replies: 1 comment 13 replies

Comment options

You must be logged in to vote
13 replies
@Kludex
Comment options

@nicoddemus
Comment options

@Kludex
Comment options

@nicoddemus
Comment options

Answer selected by Kludex
@Kludex
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants