0
私はPythonでいくつかのテストにunittestを使用しています。私は単純なテストを持っています:Pythonでのアサーションエラーメッセージの理解
self.assertEqual(stdout, expected_stdout)
本当にちょうど2つの文字列の等価性をチェックします。 私はそれを実行すると、AssertionError
が得られますが、これは意味が分かりません。例:
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
(の左側の最初の部分は、=実際の出力の右側に第2の部分は=期待されています!)。
誰でも+/-の読み取り方法を理解できますか?ありがとう
https://docs.python.org/3/library/unittest.html#unittest.TestCase.assertEqualは、「* firstとsecondは完全に同じ型です[..]型固有の等価関数は次のようになりますより有用なデフォルトのエラーメッセージ* "を生成するために呼び出され、[ここにあります](https://docs.python.org/3/library/unittest.html#unittest.TestCase.addTypeEqualityFunc)、" * a差分を強調表示している2つの文字列のdiffはエラーメッセージ*に含まれますので、削除する行と文字列に一致する行を追加します - この場合、空白の最後の '\ n' – TessellatingHeckler