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.

classification
Title: module 'unittest.mock' has no attribute 'AsyncMock'
Type: behavior Stage: resolved
Components: Versions: Python 3.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: wandermonk, xtreak
Priority: normal Keywords:

Created on 2021-08-27 07:43 by wandermonk, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (7)
msg400400 - (view) Author: Phani Kumar Yadavilli (wandermonk) Date: 2021-08-27 07:43
The unittest.mock does not have AsyncMock. I tested the same code in 3.9 it works fine.
msg400401 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2021-08-27 07:49
Can you please add a sample script to reproduce the problem. It will be also helpful to add how you run the script and also attach the error message you are getting. Given that you have selected Python 3.7 version AsyncMock was added in Python 3.8 . For Python 3.7 you might want to use the backport of mock.
msg400405 - (view) Author: Phani Kumar Yadavilli (wandermonk) Date: 2021-08-27 09:48
from unittest import mock

@mock.patch(
    "project.celerytasks.embedder.BulkEmbedder.fetch_embedding",
    mock.AsyncMock(return_value=embedding_response),
)
def test_document_embedding():

    doc = {
        "orgId": "orgtest"
    }

    doc = embed(document=doc, embedding_endpoint=embedding_endpoint)

    assert doc["subdocuments"]

    assert len(doc["title_embedding"]) == embedding_dim
    assert len(doc["subdocuments"]) == len(doc["paragraphs"])

    assert len(doc["subdocuments"][0][embedding_name]) == embedding_dim

Error:

____________________________________________________________________________________________________________________
ERROR collecting code/tests/test_embedder.py
____________________________________________________________________________________________________________________

tests/test_embedder.py:18: in <module>

    mock.AsyncMock(return_value=embedding_response),

E   AttributeError: module 'unittest.mock' has no attribute 'AsyncMock'

==============================================================================================================================
short test summary info
===============================================================================================================================

ERROR tests/test_embedder.py - AttributeError: module 'unittest.mock' has
no attribute 'AsyncMock'

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Interrupted: 1 error during collection
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

==================================================================================================================================
1 error in 6.02s
==================================================================================================================================

Regards
Phani kumar yadavilli

On Fri, Aug 27, 2021 at 1:19 PM Karthikeyan Singaravelan <
report@bugs.python.org> wrote:

>
> Karthikeyan Singaravelan <tir.karthi@gmail.com> added the comment:
>
> Can you please add a sample script to reproduce the problem. It will be
> also helpful to add how you run the script and also attach the error
> message you are getting. Given that you have selected Python 3.7 version
> AsyncMock was added in Python 3.8 . For Python 3.7 you might want to use
> the backport of mock.
>
> ----------
> nosy: +xtreak
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <https://bugs.python.org/issue45028>
> _______________________________________
>
msg400423 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2021-08-27 14:19
What version of Python are you using?
msg400424 - (view) Author: Phani Kumar Yadavilli (wandermonk) Date: 2021-08-27 14:21
I am using python 3.7.

Regards
Phani kumar yadavilli

On Fri, Aug 27, 2021 at 7:49 PM Karthikeyan Singaravelan <
report@bugs.python.org> wrote:

>
> Karthikeyan Singaravelan <tir.karthi@gmail.com> added the comment:
>
> What version of Python are you using?
>
> ----------
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <https://bugs.python.org/issue45028>
> _______________________________________
>
msg400425 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2021-08-27 14:24
AsyncMock is a feature of Python 3.8 . Please upgrade to Python 3.8 or use mock backport for AsyncMock in Python 3.7 https://github.com/testing-cabal/mock . I guess this can be closed as not a bug.
msg400426 - (view) Author: Phani Kumar Yadavilli (wandermonk) Date: 2021-08-27 14:26
Sure, will do that.
Regards
Phani kumar yadavilli

On Fri, Aug 27, 2021 at 7:54 PM Karthikeyan Singaravelan <
report@bugs.python.org> wrote:

>
> Karthikeyan Singaravelan <tir.karthi@gmail.com> added the comment:
>
> AsyncMock is a feature of Python 3.8 . Please upgrade to Python 3.8 or use
> mock backport for AsyncMock in Python 3.7
> https://github.com/testing-cabal/mock . I guess this can be closed as not
> a bug.
>
> ----------
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <https://bugs.python.org/issue45028>
> _______________________________________
>
History
Date User Action Args
2022-04-11 14:59:49adminsetgithub: 89191
2021-08-27 15:24:11xtreaksetstatus: open -> closed
type: compile error -> behavior
resolution: not a bug
stage: resolved
2021-08-27 14:26:38wandermonksetmessages: + msg400426
2021-08-27 14:24:18xtreaksetmessages: + msg400425
2021-08-27 14:21:51wandermonksetmessages: + msg400424
2021-08-27 14:19:20xtreaksetmessages: + msg400423
2021-08-27 09:48:43wandermonksetmessages: + msg400405
2021-08-27 07:49:00xtreaksetnosy: + xtreak
messages: + msg400401
2021-08-27 07:43:57wandermonkcreate