Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-124176:create_autospec must not change how dataclass defaults are mocked#124724

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
sobolevn wants to merge5 commits intopython:main
base:main
Choose a base branch
Loading
fromsobolevn:issue-124176-2
Open
Changes from1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
Add more tests
  • Loading branch information
@sobolevn
sobolevn committedOct 4, 2024
commit81b4e0022e28b47b275ab6197d36f66323af0f47
11 changes: 11 additions & 0 deletionsLib/test/test_unittest/testmock/testhelpers.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1121,6 +1121,17 @@ class WithWiderDefault:
with self.subTest(mock=mock):
self.assertIs(mock.narrow_default.__class__, int)
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel both of these tests would be clearer if they actually showed what the thing ends up being, not just it's type, something like:

Suggested change
self.assertIs(mock.narrow_default.__class__,int)
self.assertIs(mock.narrow_default.__class__,int)
self.assertEqual(mock.narrow_default,30)

ncoghlan reacted with thumbs up emoji
Copy link
Contributor

Choose a reason for hiding this comment

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

Adding something along these lines would also distinguish the cases where we're expecting to mock a specific value from those where we're deriving an instance spec from a declared runtime type


def test_dataclass_with_no_default(self):
@dataclass
class WithWiderDefault:
narrow_default: int | None

mock = create_autospec(WithWiderDefault, instance=True)
self.assertIs(mock.narrow_default.__class__, type(int | None))

mock = create_autospec(WithWiderDefault(1))
self.assertIs(mock.narrow_default.__class__, int)


class TestCallList(unittest.TestCase):

Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp