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

trailing newline in str comparison is hard to spot #324

Open
jugmac00 opened this issue Mar 13, 2022 · 0 comments
Open

trailing newline in str comparison is hard to spot #324

jugmac00 opened this issue Mar 13, 2022 · 0 comments

Comments

@jugmac00
Copy link
Contributor

testtools

$ python test_diff.py 
F
======================================================================
FAIL: test_newline (__main__.TestNewline)
__main__.TestNewline.test_newline
----------------------------------------------------------------------
testtools.testresult.real._StringException: Traceback (most recent call last):
  File "test_diff.py", line 11, in test_newline
    self.assertEqual(
  File "/tmp/venv/lib/python3.8/site-packages/testtools/testcase.py", line 393, in assertEqual
    self.assertThat(observed, matcher, message)
  File "/tmp/venv/lib/python3.8/site-packages/testtools/testcase.py", line 480, in assertThat
    raise mismatch_error
testtools.matchers._impl.MismatchError: !=:
reference = '''\
INFO Requesting CI build for  972c6d2dc6dd5efdad1377c0d224e03eb8f276f7 on focal/amd64
'''
actual    = 'INFO Requesting CI build for  972c6d2dc6dd5efdad1377c0d224e03eb8f276f7 on focal/amd64'

unittest

$ python test_diff.py 
F
======================================================================
FAIL: test_newline (__main__.TestNewline)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test_diff.py", line 11, in test_newline
    "INFO Requesting CI build for  972c6d2dc6dd5efdad1377c0d224e03eb8f276f7 on focal/amd64"
AssertionError: 'INFO[21 chars]for  972c6d2dc6dd5efdad1377c0d224e03eb8f276f7 on focal/amd64\n' != 'INFO[21 chars]for  972c6d2dc6dd5efdad1377c0d224e03eb8f276f7 on focal/amd64'
- INFO Requesting CI build for  972c6d2dc6dd5efdad1377c0d224e03eb8f276f7 on focal/amd64
?                                                                                      -
+ INFO Requesting CI build for  972c6d2dc6dd5efdad1377c0d224e03eb8f276f7 on focal/amd64

pytest

$ pytest test_diff.py 
======================================== test session starts ========================================
platform linux -- Python 3.8.10, pytest-7.0.1, pluggy-1.0.0
rootdir: /tmp
collected 1 item                                                                                    

test_diff.py F                                                                                [100%]

============================================= FAILURES ==============================================
_____________________________________ TestNewline.test_newline ______________________________________

self = <test_diff.TestNewline testMethod=test_newline>

    def test_newline(self):
>       self.assertEqual(
            newline(),
            "INFO Requesting CI build for  972c6d2dc6dd5efdad1377c0d224e03eb8f276f7 on focal/amd64"
        )
E       AssertionError: 'INFO[21 chars]for  972c6d2dc6dd5efdad1377c0d224e03eb8f276f7 on focal/amd64\n' != 'INFO[21 chars]for  972c6d2dc6dd5efdad1377c0d224e03eb8f276f7 on focal/amd64'
E       - INFO Requesting CI build for  972c6d2dc6dd5efdad1377c0d224e03eb8f276f7 on focal/amd64
E       ?                                                                                      -
E       + INFO Requesting CI build for  972c6d2dc6dd5efdad1377c0d224e03eb8f276f7 on focal/amd64

test_diff.py:11: AssertionError

Both unittest and pytest indicate what the problem is, but testtools only shows a rather unfortunate multiline representation of the string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants