classification
Title: assertEqual doesn't use maxDiff when comparing dictionaries
Type: behavior Stage: resolved
Components: Tests Versions: Python 3.6
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Victor Engmark2, iritkatriel, prudvinit, xtreak
Priority: normal Keywords:

Created on 2018-08-27 02:21 by Victor Engmark2, last changed 2020-10-20 11:01 by iritkatriel. This issue is now closed.

Files
File name Uploaded Description Edit
bpo34514.py xtreak, 2018-08-27 08:08
Messages (6)
msg324140 - (view) Author: Victor Engmark (Victor Engmark2) Date: 2018-08-27 02:21
According to the documentation `assertDictEqual()` "will be used by default to compare dictionaries in calls to assertEqual()." Great, since `maxDiff` applies to assertDictEqual(). However, `maxDiff` doesn't apply to `assertEqual()` when comparing dictionaries.
msg324141 - (view) Author: Prudvi RajKumar Maddala (prudvinit) * Date: 2018-08-27 02:58
Hello Victor, can you tell me what is 'maxDiff'? Can you give me a simple example of expected output and actual output by taking a simple dictionary?

Thanks
msg324153 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2018-08-27 07:51
@prudvinit 

Reference : https://docs.python.org/3.8/library/unittest.html#unittest.TestCase.maxDiff

> This attribute controls the maximum length of diffs output by assert methods that report diffs on failure. It defaults to 80*8 characters. Assert methods affected by this attribute are assertSequenceEqual() (including all the sequence comparison methods that delegate to it), assertDictEqual() and assertMultiLineEqual().

Thanks
msg324154 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2018-08-27 08:08
@victor I am little confused over the issue since you have said "`assertDictEqual()` "will be used by default to compare dictionaries in calls to assertEqual()" and "`maxDiff` doesn't apply to `assertEqual()` when comparing dictionaries" . Since assertDictEqual is used for assertEqual calls when they compare dictionaries I can see that maxDiff value is applied to the diffs. A script will be helpful here on the expected and actual output. The attached script I have used to check that the maxDiff value is applied.


$ ./python.exe ../backups/bpo34514.py

FFFF
======================================================================
FAIL: test_assert_dict_equal_large_diff (__main__.Test_TestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "../backups/bpo34514.py", line 59, in test_assert_dict_equal_large_diff
    self.assertDictEqual(original, expected)
AssertionError: {1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, 7: 7, [726 chars]: 99} != {101: 101, 102: 102, 103: 103, 104: 104, 10[942 chars] 199}
Diff is 3347 characters long. Set self.maxDiff to None to see it.

======================================================================
FAIL: test_assert_dict_equal_small_diff (__main__.Test_TestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "../backups/bpo34514.py", line 31, in test_assert_dict_equal_small_diff
    self.assertDictEqual(original, expected)
AssertionError: {1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, 7: 7, 8: 8, 9: 9} != {101: 101, 102: 102, 103: 103, 104: 104, 10[42 chars] 109}
- {1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, 7: 7, 8: 8, 9: 9}
+ {101: 101,
+  102: 102,
+  103: 103,
+  104: 104,
+  105: 105,
+  106: 106,
+  107: 107,
+  108: 108,
+  109: 109}

======================================================================
FAIL: test_assert_equal_large_diff (__main__.Test_TestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "../backups/bpo34514.py", line 45, in test_assert_equal_large_diff
    self.assertEqual(original, expected)
AssertionError: {1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, 7: 7, [726 chars]: 99} != {101: 101, 102: 102, 103: 103, 104: 104, 10[942 chars] 199}
Diff is 3347 characters long. Set self.maxDiff to None to see it.

======================================================================
FAIL: test_assert_equal_small_diff (__main__.Test_TestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "../backups/bpo34514.py", line 17, in test_assert_equal_small_diff
    self.assertEqual(original, expected)
AssertionError: {1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, 7: 7, 8: 8, 9: 9} != {101: 101, 102: 102, 103: 103, 104: 104, 10[42 chars] 109}
- {1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, 7: 7, 8: 8, 9: 9}
+ {101: 101,
+  102: 102,
+  103: 103,
+  104: 104,
+  105: 105,
+  106: 106,
+  107: 107,
+  108: 108,
+  109: 109}

----------------------------------------------------------------------
Ran 4 tests in 3.496s

FAILED (failures=4)


Thanks
msg324189 - (view) Author: Prudvi RajKumar Maddala (prudvinit) * Date: 2018-08-27 17:36
I see that maxDiff is applied correctly when comparing dictionaries. I don't think that's an issue.
msg377071 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2020-09-17 22:58
I think this can be closed as not a bug, unless Victor can clarify with an example script why there is an issue.
History
Date User Action Args
2020-10-20 11:01:58iritkatrielsetstatus: open -> closed
resolution: not a bug
stage: resolved
2020-09-17 22:58:18iritkatrielsetnosy: + iritkatriel
messages: + msg377071
2018-08-27 17:36:54prudvinitsetmessages: + msg324189
2018-08-27 08:08:54xtreaksetfiles: + bpo34514.py

messages: + msg324154
2018-08-27 07:51:08xtreaksetnosy: + xtreak
messages: + msg324153
2018-08-27 02:58:24prudvinitsetnosy: + prudvinit
messages: + msg324141
2018-08-27 02:21:09Victor Engmark2create