Skip to content

Conversation

@ragulpr
Copy link
Contributor

@ragulpr ragulpr commented Sep 12, 2023

Fixes #109350

Updates the captured output/exceptions that are not reflecting the current (more readable) exceptions (Doc/library/unittest.mock.rst, Doc/library/unittest.mock-examples.rst) .

I ran this @ Python 3.13.0a0, I'm sure it can be backported far back but I'm not up to the task right now.


📚 Documentation preview 📚: https://cpython-previews--109353.org.readthedocs.build/

@ghost
Copy link

ghost commented Sep 12, 2023

All commit authors signed the Contributor License Agreement.
CLA signed

Comment on lines 959 to 962
>>> mock.method.assert_awaited_once()
Traceback (most recent call last):
...
AssertionError: Expected mock to have been awaited once. Awaited 2 times.
AssertionError: Expected method to have been awaited once. Awaited 0 times.
Copy link
Contributor Author

@ragulpr ragulpr Sep 12, 2023

Choose a reason for hiding this comment

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

This is the actual but likely not the intended output, if called with mock.assert_awaited_once() rather than mock.method.assert_awaited_once() it yields the output that was documented. Should I change it immediately or spawn separate issue?

Copy link
Contributor

Choose a reason for hiding this comment

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

Fix it here :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Awesome! Done d7f3b13

@sobolevn sobolevn requested a review from cjw296 September 14, 2023 22:21
Copy link
Contributor

@cjw296 cjw296 left a comment

Choose a reason for hiding this comment

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

Fantastic, thanks for this!

Comment on lines 959 to 962
>>> mock.method.assert_awaited_once()
Traceback (most recent call last):
...
AssertionError: Expected mock to have been awaited once. Awaited 2 times.
AssertionError: Expected method to have been awaited once. Awaited 0 times.
Copy link
Contributor

Choose a reason for hiding this comment

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

Fix it here :-)

ragulpr and others added 2 commits September 15, 2023 11:52
Run with
```
import asyncio
import unittest
from unittest.mock import Mock, MagicMock, AsyncMock, patch, call, sentinel

mock = AsyncMock()
async def main():
    await mock()

asyncio.run(main())
mock.assert_awaited_once()
asyncio.run(main())
mock.assert_awaited_once()
```
@ragulpr
Copy link
Contributor Author

ragulpr commented Sep 15, 2023

Done! It's not much but it's something 😁

EDIT: Not my fault builds are failing

@cjw296 cjw296 merged commit 3d88145 into python:main Sep 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation in the Doc dir skip news

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Captured output in unittest.mock documentation is outdated

2 participants