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

bpo-44686 replace unittest.mock._importer with pkgutil.resolve_name #18544

Merged
merged 5 commits into from
Jul 21, 2021

Conversation

graingert
Copy link
Contributor

@graingert graingert commented Feb 18, 2020

https://bugs.python.org/issue44686

Automerge-Triggered-By: GH:cjw296

@codecov
Copy link

codecov bot commented Feb 18, 2020

Codecov Report

Merging #18544 into master will decrease coverage by 0.05%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #18544      +/-   ##
==========================================
- Coverage   83.25%   83.20%   -0.06%     
==========================================
  Files        1571     1571              
  Lines      414749   414735      -14     
  Branches    44456    44453       -3     
==========================================
- Hits       345300   345068     -232     
- Misses      59795    60019     +224     
+ Partials     9654     9648       -6     
Impacted Files Coverage Δ
Lib/distutils/tests/test_bdist_rpm.py 30.00% <0.00%> (-65.00%) ⬇️
Lib/distutils/command/bdist_rpm.py 7.63% <0.00%> (-56.88%) ⬇️
Lib/test/test_urllib2net.py 76.92% <0.00%> (-13.85%) ⬇️
Lib/test/test_smtpnet.py 78.57% <0.00%> (-7.15%) ⬇️
Lib/ftplib.py 63.85% <0.00%> (-6.06%) ⬇️
Lib/test/test_ftplib.py 87.11% <0.00%> (-4.72%) ⬇️
Tools/scripts/db2pickle.py 17.82% <0.00%> (-3.97%) ⬇️
Tools/scripts/pickle2db.py 16.98% <0.00%> (-3.78%) ⬇️
Lib/test/test_socket.py 71.94% <0.00%> (-3.77%) ⬇️
Lib/test/test_asyncio/test_base_events.py 91.84% <0.00%> (-3.30%) ⬇️
... and 46 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8edfc47...077c3bc. Read the comment docs.

@tirkarthi
Copy link
Member

I think this deserves a discussion and a bpo. @cjw296 this uses pkgutil.resolve_name which is a new feature in 3.9 and the backport needs to accommodate the change if merged.

@@ -1583,8 +1565,7 @@ def _get_target(target):
except (TypeError, ValueError):
raise TypeError("Need a valid target to patch. You supplied: %r" %
(target,))
getter = lambda: _importer(target)
return getter, attribute
return partial(pkgutil.resolve_name, target), attribute
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason here to be using functools.partial over lambda?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for consistency. lambda: is used twice in this file whereas partial( is used six times

@cjw296
Copy link
Contributor

cjw296 commented May 21, 2020

@tirkarthi: Looking at the diff, we could probably just skip backporting this one...

@graingert graingert requested a review from cjw296 as a code owner July 20, 2021 19:22
@graingert graingert changed the title replace unittest.mock._importer with pkgutil.resolve_name bpo-44686 replace unittest.mock._importer with pkgutil.resolve_name Jul 20, 2021
@graingert graingert requested a review from FFY00 July 20, 2021 19:49
@graingert
Copy link
Contributor Author

I think this deserves a discussion and a bpo. @cjw296 this uses pkgutil.resolve_name which is a new feature in 3.9 and the backport needs to accommodate the change if merged.

I've now created the bpo

@miss-islington
Copy link
Contributor

@graingert: Status check is done, and it's a success ❌ .

@miss-islington
Copy link
Contributor

@graingert: Status check is done, and it's a success ✅ .

@miss-islington
Copy link
Contributor

Sorry, I can't merge this PR. Reason: 3 of 5 required status checks have not succeeded: 1 expected..

@miss-islington
Copy link
Contributor

@graingert: Status check is done, and it's a success ✅ .

@miss-islington miss-islington merged commit ab7fcc8 into python:main Jul 21, 2021
@graingert graingert deleted the patch-3 branch July 21, 2021 11:48
d-fence added a commit to odoo-dev/odoo that referenced this pull request Feb 10, 2023
Since python/cpython#18544, unittest mock is not able to properly find
the "odoo.tools.config".

When trying to patch the `options` dictionnary, it leads to
`AttributeError: module 'odoo.tools.config' has no attribute 'options'`

In order to have the tests
working in python <= 3.11, we have to import the config module and patch
the options in place.
robodoo pushed a commit to odoo/odoo that referenced this pull request Feb 10, 2023
Since python/cpython#18544, unittest mock is not able to properly find
the "odoo.tools.config".

When trying to patch the `options` dictionnary, it leads to
`AttributeError: module 'odoo.tools.config' has no attribute 'options'`

In order to have the tests
working in python <= 3.11, we have to import the config module and patch
the options in place.

Part-of: #112317
fw-bot pushed a commit to odoo-dev/odoo that referenced this pull request Feb 10, 2023
Since python/cpython#18544, unittest mock is not able to properly find
the "odoo.tools.config".

When trying to patch the `options` dictionnary, it leads to
`AttributeError: module 'odoo.tools.config' has no attribute 'options'`

In order to have the tests
working in python <= 3.11, we have to import the config module and patch
the options in place.

X-original-commit: 482cb08
d-fence added a commit to odoo-dev/odoo that referenced this pull request Feb 13, 2023
Since python/cpython#18544, unittest mock is not able to properly find
the "odoo.tools.config".

When trying to patch the `options` dictionnary, it leads to
`AttributeError: module 'odoo.tools.config' has no attribute 'options'`

In order to have the tests
working in python <= 3.11, we have to import the config module and patch
the options in place.
robodoo pushed a commit to odoo/odoo that referenced this pull request Feb 13, 2023
Since python/cpython#18544, unittest mock is not able to properly find
the "odoo.tools.config".

When trying to patch the `options` dictionnary, it leads to
`AttributeError: module 'odoo.tools.config' has no attribute 'options'`

In order to have the tests
working in python <= 3.11, we have to import the config module and patch
the options in place.

X-original-commit: 482cb08
Part-of: #112440
robodoo pushed a commit to odoo/odoo that referenced this pull request Feb 14, 2023
Since python/cpython#18544, unittest mock is not able to properly find
the "odoo.tools.config".

When trying to patch the `options` dictionnary, it leads to
`AttributeError: module 'odoo.tools.config' has no attribute 'options'`

In order to have the tests
working in python <= 3.11, we have to import the config module and patch
the options in place.

Part-of: #112450
StevenSermeus pushed a commit to acsone/odoo that referenced this pull request Mar 9, 2023
Since python/cpython#18544, unittest mock is not able to properly find
the "odoo.tools.config".

When trying to patch the `options` dictionnary, it leads to
`AttributeError: module 'odoo.tools.config' has no attribute 'options'`

In order to have the tests
working in python <= 3.11, we have to import the config module and patch
the options in place.

Part-of: odoo#112317
Xavier-Do pushed a commit to odoo-dev/odoo that referenced this pull request Mar 13, 2024
Since python/cpython#18544, unittest mock is not able to properly find
the "odoo.tools.config".

When trying to patch the `options` dictionnary, it leads to
`AttributeError: module 'odoo.tools.config' has no attribute 'options'`

In order to have the tests
working in python <= 3.11, we have to import the config module and patch
the options in place.
Xavier-Do pushed a commit to odoo-dev/odoo that referenced this pull request Mar 28, 2024
Since python/cpython#18544, unittest mock is not able to properly find
the "odoo.tools.config".

When trying to patch the `options` dictionnary, it leads to
`AttributeError: module 'odoo.tools.config' has no attribute 'options'`

In order to have the tests
working in python <= 3.11, we have to import the config module and patch
the options in place.
robodoo pushed a commit to odoo/odoo that referenced this pull request Mar 29, 2024
Since python/cpython#18544, unittest mock is not able to properly find
the "odoo.tools.config".

When trying to patch the `options` dictionnary, it leads to
`AttributeError: module 'odoo.tools.config' has no attribute 'options'`

In order to have the tests
working in python <= 3.11, we have to import the config module and patch
the options in place.

Part-of: #151989
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants