0

I'm using unittest for some testing in Python. I have a simple test:

self.assertEqual(stdout, expected_stdout)

that really just checks the equality of two strings. When I run it I get an AssertionError, which is fine, but I'm not sure what the +/- below it mean. Example:

FAIL: unittest.case.FunctionTestCase (basic_test4)
actually pretty irrelevant
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/h/u16/c4/00/chenjoh6/csc209_advance_prep_ta/209-materials/assignments/a2/file-archive/20179/testing/a2_fs.py", line 33, in inner_meth_
    simple_test(["asd"], tc.dict_of_tests[name][1], tc.dict_of_tests[name][2] ,tc.dict_of_tests[name][0])(tfs)
  File "/h/u16/c4/00/chenjoh6/csc209_advance_prep_ta/209-materials/autotesting/20179/test_helpers.py", line 111, in _t
    self.assertEqual(stderr, expected_stderr)
AssertionError: 'or is it here(null)This is problemjohn\njohn: Success\n' != 'or is it here(null)john: Success\n'
+ or is it here(null)john: Success
- or is it here(null)This is problemjohn
- john: Success

(The first part to the left of the != is the actual output, the second part to the right of the != is the expected).

Can anyone help me understand how to read the +/-? Thanks

1
  • docs.python.org/3/library/… says "if first and second are the exact same type [..] the type-specific equality function will be called in order to generate a more useful default error message", and that is here it says "a diff of the two strings highlighting the differences will be included in the error message", so it's telling you which lines to remove and which to add to match the strings - in this case all of them except the blank last \n Commented Aug 8, 2017 at 1:23

1 Answer 1

1

It is a line difference comparison of the two strings to change the left hand side to the right hand side. + means you have to add the line or is it here(null)john: Success and - means to remove the lines or is it here(null) this is problemjohn and john: Success.

Since the left side only contains the two lines removed, and the right side only contains the one line added, that should make sense. In this case a difference isn't very useful, but if the lines had more in common the difference would help narrow down the reason for the failure.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.