Skip to content
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

unittest.patch confuses modules with base modules #86701

Open
twolodzko mannequin opened this issue Dec 2, 2020 · 2 comments
Open

unittest.patch confuses modules with base modules #86701

twolodzko mannequin opened this issue Dec 2, 2020 · 2 comments
Labels
3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@twolodzko
Copy link
Mannequin

twolodzko mannequin commented Dec 2, 2020

BPO 42535
Nosy @tirkarthi, @twolodzko, @akulakov

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = None
created_at = <Date 2020-12-02.11:14:10.667>
labels = ['3.7', 'type-bug', 'library']
title = 'unittest.patch confuses modules with base modules'
updated_at = <Date 2021-07-17.14:15:49.350>
user = 'https://github.com/twolodzko'

bugs.python.org fields:

activity = <Date 2021-07-17.14:15:49.350>
actor = 'andrei.avk'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Library (Lib)']
creation = <Date 2020-12-02.11:14:10.667>
creator = 'twolodzko'
dependencies = []
files = []
hgrepos = []
issue_num = 42535
keywords = []
message_count = 2.0
messages = ['382303', '397723']
nosy_count = 3.0
nosy_names = ['xtreak', 'twolodzko', 'andrei.avk']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue42535'
versions = ['Python 3.7']

@twolodzko
Copy link
Mannequin Author

twolodzko mannequin commented Dec 2, 2020

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 mymodule.nestedmodule.io, 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('mymodule.nestedmodule.io.foo'):
    bar()

The problem is, when running the test I get the following error: AttributeError: <module 'io' from '/usr/local/lib/python3.7/io.py'> 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.

@twolodzko twolodzko mannequin added 3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Dec 2, 2020
@akulakov
Copy link
Contributor

I've tested this in both 3.7.7 and 3.9.1 and could not reproduce.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
Status: No status
Development

No branches or pull requests

1 participant