-
-
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
AttributeError: Test modules cannot use parent module's attributes under --import-mode=importlib
#10337
Comments
Have the required fix lined up in #10338. Please let me know if it looks good or I am missing something. Thanks! |
any thoughts on this ? @nicoddemus / @RonnyPfannschmidt / @bluetech |
This issue also affects pmxbot. I created an even smaller repro with one namespace package, one submodule, and one test:
Remove Also confirmed that the bugfix proposed in #10338 fixes the issue:
|
I've also confirmed that with this fix, pmxbot is able to adopt native namespace packages without the test suite failing (pmxbot/pmxbot#110). Thanks Akhil for the report and fix. |
Really sorry, I seem to have missed this. Yeah looks great, it is only missing a changelog entry which I will push up shortly. Would you like to have your name added to AUTHORS as well @akhilramkee ? |
Failing to add child modules as attributes of parent module will prevent them from being accessible through parent module. Fix #10337
Thanks @nicoddemus for taking care of the missing changelog.
Sure, I would like that. I can add myself to the AUTHORS in a separate PR if that works. |
This PR contains the following updates: | Package | Update | Change | |---|---|---| | [pytest](https://docs.pytest.org/en/latest/) ([source](https://github.com/pytest-dev/pytest), [changelog](https://docs.pytest.org/en/stable/changelog.html)) | patch | `==7.4.0` -> `==7.4.2` | --- ### Release Notes <details> <summary>pytest-dev/pytest (pytest)</summary> ### [`v7.4.2`](https://github.com/pytest-dev/pytest/releases/tag/7.4.2): pytest 7.4.2 (2023-09-07) [Compare Source](pytest-dev/pytest@7.4.1...7.4.2) ### Bug Fixes - [#​11237](pytest-dev/pytest#11237): Fix doctest collection of `functools.cached_property` objects. - [#​11306](pytest-dev/pytest#11306): Fixed bug using `--importmode=importlib` which would cause package `__init__.py` files to be imported more than once in some cases. - [#​11367](pytest-dev/pytest#11367): Fixed bug where `user_properties` where not being saved in the JUnit XML file if a fixture failed during teardown. - [#​11394](pytest-dev/pytest#11394): Fixed crash when parsing long command line arguments that might be interpreted as files. ### Improved Documentation - [#​11391](pytest-dev/pytest#11391): Improved disclaimer on pytest plugin reference page to better indicate this is an automated, non-curated listing. ### [`v7.4.1`](https://github.com/pytest-dev/pytest/releases/tag/7.4.1): pytest 7.4.1 (2023-09-02) [Compare Source](pytest-dev/pytest@7.4.0...7.4.1) ## Bug Fixes - [#​10337](pytest-dev/pytest#10337): Fixed bug where fake intermediate modules generated by `--import-mode=importlib` would not include the child modules as attributes of the parent modules. - [#​10702](pytest-dev/pytest#10702): Fixed error assertion handling in `pytest.approx` when `None` is an expected or received value when comparing dictionaries. - [#​10811](pytest-dev/pytest#10811): Fixed issue when using `--import-mode=importlib` together with `--doctest-modules` that caused modules to be imported more than once, causing problems with modules that have import side effects. </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNi44LjExIiwidXBkYXRlZEluVmVyIjoiMzYuMTA3LjIiLCJ0YXJnZXRCcmFuY2giOiJtYXN0ZXIifQ==--> Reviewed-on: https://git.apud.pl/jacek/adventofcode/pulls/32 Co-authored-by: Renovate <renovate@apud.pl> Co-committed-by: Renovate <renovate@apud.pl>
pip list
from the virtual environment you are usingDescription of the bug:
Pytest when executed under
--import-mode=importlib
doesn't try to retain the child module as parent module's attribute if parent module is already insys.path
. This started happening in pytest 7.1.3 after enabling doctest to respectimport-mode
in #10088.Minimal Example
File structure
temp.py
test_temp.py
Output - MacOS 12.6
pytest7.1.3 without importlib
pytest-7.1.3 with importlib
It could be seen that the failure happens when we try to access the child module through parent module.
pytest-7.0.1 with importlib
This passes, because doctest-modules were using
prepend
instead ofimportlib
before the PR. ( added this to state this is a recent issue ).Fix: Child module has to be persisted in Parent module as an attribute similar to how
importlib.import_module
does.The text was updated successfully, but these errors were encountered: