This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: unittest.patch confuses modules with base modules
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.7
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: andrei.avk, twolodzko, xtreak
Priority: normal Keywords:

Created on 2020-12-02 11:14 by twolodzko, last changed 2022-04-11 14:59 by admin.

Messages (2)
msg382303 - (view) Author: Tymek Wołodźko (twolodzko) * Date: 2020-12-02 11:14
Nonetheless having several attempts, I wasn't able to create reproducible example for this bug, but I will try describing it in detail.

I have a package with multiple modules. One of the paths is like ``, among other functions, this module contains functions `foo()` and `bar()`, where `bar()` does call `foo()`. The module *does not* import base python's `io` module. I have a unit test that patches:

with path(''):

The problem is, when running the test I get the following error: `AttributeError: <module 'io' from '/usr/local/lib/python3.7/'> does not have the attribute 'foo'`. The problem is solved when I rename `io` to `myio` and correct all the paths to use the new name.
msg397723 - (view) Author: Andrei Kulakov (andrei.avk) * (Python triager) Date: 2021-07-17 14:15
I've tested this in both 3.7.7 and 3.9.1 and could not reproduce.
Date User Action Args
2022-04-11 14:59:38adminsetgithub: 86701
2021-07-17 14:15:49andrei.avksetnosy: + andrei.avk
messages: + msg397723
2020-12-02 11:51:29xtreaksetnosy: + xtreak
2020-12-02 11:14:10twolodzkocreate