[issue19217] Calling assertEquals for moderately long list takes too long

STINNER Victor report at bugs.python.org
Wed Feb 8 03:36:47 EST 2017


STINNER Victor added the comment:

unittest_unified_diff.patch: Rebased patch for the default branch. My patch updates also unit tests.

The patch changes the test output. If we decide to apply the patch, I propose to only apply it to the default branch (Python 3.7).

The bug report is about a test which fails. I'm not sure that it's a real blocker issue that Python is slow when a test fails. At least, it should be fast when a test pass. I mean that I like the current output, I'm not sure about the new output.

Example with attached unified_diff.py.

Before:
@@@@@@@@@@@@@@@@@
F
======================================================================
FAIL: test_x (__main__.Test)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "unified_diff.py", line 5, in test_x
    self.assertEqual([], [None])
AssertionError: Lists differ: [] != [None]

Second list contains 1 additional elements.
First extra element 0:
None

- []
+ [None]

----------------------------------------------------------------------
Ran 1 test in 0.001s

FAILED (failures=1)
@@@@@@@@@@@@@@@@@

With the patch:
@@@@@@@@@@@@@@@@@
haypo at selma$ ./python unified_diff.py 
F
======================================================================
FAIL: test_x (__main__.Test)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "unified_diff.py", line 5, in test_x
    self.assertEqual([], [None])
AssertionError: Lists differ: [] != [None]

Second list contains 1 additional elements.
First extra element 0:
None

--- 
+++ 
@@ -1 +1 @@
-[]
+[None]

----------------------------------------------------------------------
Ran 1 test in 0.001s

FAILED (failures=1)
@@@@@@@@@@@@@@@@@


The patch adds the following header which can be suprising:
@@@@@@@@@@@@@@@@@
--- 
+++ 
@@ -1 +1 @@
@@@@@@@@@@@@@@@@@


Maybe we should pass a "file name" to unified_diff() to get something like:
@@@@@@@@@@@@@@@@@
--- expected
+++ got
@@ -1 +1 @@
@@@@@@@@@@@@@@@@@

----------
Added file: http://bugs.python.org/file46573/unittest_unified_diff.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue19217>
_______________________________________


More information about the Python-bugs-list mailing list