-
-
Notifications
You must be signed in to change notification settings - Fork 33.3k
gh-109350: Fix outdated captured output in unittest.mock documentation #109353
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
Conversation
cee4fb3 to
03cbebf
Compare
Doc/library/unittest.mock.rst
Outdated
| >>> 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. |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix it here :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! Done d7f3b13 ✅
cjw296
left a comment
There was a problem hiding this 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!
Doc/library/unittest.mock.rst
Outdated
| >>> 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix it here :-)
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()
```
|
Done! It's not much but it's something 😁 EDIT: Not my fault builds are failing |
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/