Last active
March 24, 2023 01:34
-
-
Save audiolion/fcba115f74b99d980bd6124f4b051fd6 to your computer and use it in GitHub Desktop.
pytest assert vs self.assertEqual
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TestSomething(TestCase): | |
def test_something(self): | |
assert something['message'] == 'Asserting that a very long message statement is as expected in this test case here, the issue is that its all on one line with no easy way to conform to PEP-8 besides adding "\" to continue the one line statement in python.' | |
self.assertEqual( | |
something['message'], | |
('Asserting that a very long message statement is as expected' | |
' in this test case here, the issue is that its all on one line' | |
' with no easy way to conform to PEP-8 besides adding "\" to' | |
' continue the one line statement in python.' | |
' With assertEqual and the function structure we can easily' | |
' break up a long assert statement to make it readable and' | |
' PEP-8 compliant.') | |
) |
would you recommend to always use pytest assert ?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In this case, I'd recommend using parens to define a variable
expected
and assert equality with that.I've put this into a runnable file, with one difference in the text.
test_example.py
Run it and you'll see that the pytest assert description is way better. :)
The pytest version points directly to the character that's different.
assertEqual:
assert (pytest assert rewritten version):