8000 Align Expected and Actual titles in assert_has_calls/assert_called_with for greater readability · Issue #111019 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

Align Expected and Actual titles in assert_has_calls/assert_called_with for greater readability #111019

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

Closed
morisja opened this issue Oct 18, 2023 · 1 comment
Labels
tests Tests in the Lib/test dir type-feature A feature request or enhancement

Comments

@morisja
Copy link
Contributor
morisja commented Oct 18, 2023

Feature or enhancement

Proposal:

The current output for assert_called_with and assert_has_calls has different spacing making visual identification of simple issues challenging.

Example:

  File "/usr/lib/python3.10/unittest/mock.py", line 929, in assert_called_with
    raise AssertionError(_error_message()) from cause
AssertionError: expected call not found.
Expected: mock('foo', 'bar')
Actual: mock('foo', 'foo')     <-- moving this two chars to the right would be easier to see foo != bar

  File "/usr/lib/python3.10/unittest/mock.py", line 966, in assert_has_calls
    raise AssertionError(
AssertionError: Calls not found.
Expected: [call('foo', 'bar')]
Actual: [call('foo', 'foo')]   <-- moving this two chars to the right would be easier to see foo != bar

I propose whitespace is added preceding Actual: to align as follows:

  File "/usr/lib/python3.10/unittest/mock.py", line 929, in assert_called_with
    raise AssertionError(_error_message()) from cause
AssertionError: expected call not found.
Expected: mock('foo', 'bar')
  Actual: mock('foo', 'foo')

  File "/usr/lib/python3.10/unittest/mock.py", line 966, in assert_has_calls
    raise AssertionError(
AssertionError: Calls not found.
Expected: [call('foo', 'bar')]
  Actual: [call('foo', 'foo')]

I chose preceding to minimize any potential parsing (e.g Actual : would make two fields if split by whitespace)

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

I found similar, but not exact discussion here
#79681

Linked PRs

@morisja morisja added the type-feature A feature request or enhancement label Oct 18, 2023
morisja added a commit to morisja/cpython that referenced this issue Oct 18, 2023
Align expected and actual titles in output from
assert_has_calls/assert_called_with for greater readability
morisja added a commit to morisja/cpython that referenced this issue Oct 18, 2023
Align expected and actual titles in output from
assert_has_calls/assert_called_with for greater readability
@Eclips4 Eclips4 added the tests Tests in the Lib/test dir label Oct 18, 2023
cjw296 pushed a commit that referenced this issue Oct 18, 2023
Align expected and actual titles in output from
assert_has_calls/assert_called_with for greater readability
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Oct 18, 2023
…honGH-111020)

Align expected and actual titles in output from
assert_has_calls/assert_called_with for greater readability
(cherry picked from commit 77dbd95)

Co-authored-by: James <morisja@gmail.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Oct 18, 2023
…honGH-111020)

Align expected and actual titles in output from
assert_has_calls/assert_called_with for greater readability
(cherry picked from commit 77dbd95)

Co-authored-by: James <morisja@gmail.com>
cjw296 pushed a commit that referenced this issue Oct 18, 2023
…-111020) (#111024)

gh-111019: Align expected and actual titles in test output (GH-111020)

Align expected and actual titles in output from
assert_has_calls/assert_called_with for greater readability
(cherry picked from commit 77dbd95)

Co-authored-by: James <morisja@gmail.com>
cjw296 pushed a commit that referenced this issue Oct 18, 2023
…-111020) (#111025)

gh-111019: Align expected and actual titles in test output (GH-111020)

Align expected and actual titles in output from
assert_has_calls/assert_called_with for greater readability
(cherry picked from commit 77dbd95)

Co-authored-by: James <morisja@gmail.com>
@github-project-automation github-project-automation bot moved this from Todo to Done in Unittest issues Oct 18, 2023
@terryjreedy
Copy link
Member

An alternative would have been to click 'Expected' to 'Actual', but verb-adjective is a bit jarring. Indent is fine and alignment will help.

danigm added a commit to danigm/pytest-mock that referenced this issue Dec 20, 2023
nicoddemus pushed a commit to pytest-dev/pytest-mock that referenced this issue Dec 20, 2023
aisk pushed a commit to aisk/cpython that referenced this issue Feb 11, 2024
…hon#111020)

Align expected and actual titles in output from
assert_has_calls/assert_called_with for greater readability
Glyphack pushed a commit to Glyphack/cpython that referenced this issue Sep 2, 2024
…hon#111020)

Align expected and actual titles in output from
assert_has_calls/assert_called_with for greater readability
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests Tests in the Lib/test dir type-feature A feature request or enhancement
Projects
Status: Done
Development

No branches or pull requests

4 participants
0