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

AsyncMock add .awaited like .called #82342

Closed
lisroach opened this issue Sep 13, 2019 · 7 comments
Closed

AsyncMock add .awaited like .called #82342

lisroach opened this issue Sep 13, 2019 · 7 comments
Labels
3.8 only security fixes 3.9 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@lisroach
Copy link
Contributor

BPO 38161
Nosy @lisroach, @tirkarthi
PRs
  • bpo-38161: Removes _AwaitEvent from AsyncMock. #16443
  • [3.8] bpo-38161: Removes _AwaitEvent from AsyncMock. (GH-16443) #16481
  • 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 2019-09-13.15:49:28.578>
    labels = ['type-feature', '3.8', '3.9']
    title = 'AsyncMock add `.awaited` like `.called`'
    updated_at = <Date 2019-09-30.04:23:36.840>
    user = 'https://github.com/lisroach'

    bugs.python.org fields:

    activity = <Date 2019-09-30.04:23:36.840>
    actor = 'lisroach'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = []
    creation = <Date 2019-09-13.15:49:28.578>
    creator = 'lisroach'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 38161
    keywords = ['patch']
    message_count = 6.0
    messages = ['352345', '352352', '352828', '353427', '353529', '353532']
    nosy_count = 2.0
    nosy_names = ['lisroach', 'xtreak']
    pr_nums = ['16443', '16481']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue38161'
    versions = ['Python 3.8', 'Python 3.9']

    @lisroach
    Copy link
    Contributor Author

    Currently Mock has a .called attribute, we could add an equivalent .awaited that returns True or False if the object has been awaited on.

    @tirkarthi
    Copy link
    Member

    awaited is now initialized with an Event object. Do you had any use case in mind while designing it? I think it's a good choice to have True/False instead of being used to give an Event object that is not used.

    @tirkarthi tirkarthi added 3.8 only security fixes 3.9 only security fixes type-feature A feature request or enhancement labels Sep 13, 2019
    @lisroach
    Copy link
    Contributor Author

    Yeah I think the current awaited ought to at least be a private variable, since people will assume it works like a boolean to match .called. Then we could add a new, proper, awaited that would function like:

    >>> mock = AsyncMock()
    >>> cr_mock = mock()
    >>> mock.called
    True
    >>> mock.awaited
    False
    >>> await cr_mock
    >>> mock.awaited
    True

    @lisroach
    Copy link
    Contributor Author

    Looking at this more, I think I want to just remove the current awaited object. The PR in asyntest makes it seem pretty cool: Martiusweb/asynctest#64

    But I have issue with the naming (await_event is probably better for us), and I'm not sure how to document it well and ensure it's well tested.

    With the 3.8 release coming up fast I'd rather remove it for now and then add it back in after some more thought has been given to the feature, instead of getting stuck with a not fully thought out attribute we have to worry about deprecating.

    @lisroach
    Copy link
    Contributor Author

    New changeset 25e115e by Lisa Roach in branch 'master':
    bpo-38161: Removes _AwaitEvent from AsyncMock. (GH-16443)
    25e115e

    @lisroach
    Copy link
    Contributor Author

    New changeset 36e7e4a by Lisa Roach (Miss Islington (bot)) in branch '3.8':
    bpo-38161: Removes _AwaitEvent from AsyncMock. (GH-16443) (GH-16481)
    36e7e4a

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @iritkatriel iritkatriel added the stdlib Python modules in the Lib dir label Nov 26, 2023
    @erlend-aasland
    Copy link
    Contributor

    Lisa retargeted this issue to instead remove the .awaited member from AsyncMock (this was done with #16443). The retargeted issue has been resolved; closing this issue.

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.8 only security fixes 3.9 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants