summaryrefslogtreecommitdiff
path: root/testing/test_assertion.py
diff options
context:
space:
mode:
authorDaniel Hahler <git@thequod.de>2019-11-08 04:04:23 +0100
committerDaniel Hahler <git@thequod.de>2019-11-08 04:07:09 +0100
commitcc503c1821e709376d9a05ee4f6459e4e4f41a0c (patch)
treee652fd08ac7f120dfdca9212478f8b5923b8b500 /testing/test_assertion.py
parent6ad95716dacd8448df7d4d4d3a5f759d32c17418 (diff)
downloadpytest-cc503c1821e709376d9a05ee4f6459e4e4f41a0c.tar.gz
_compare_eq_iterable: use AlwaysDispatchingPrettyPrinter
This fixes/removes the previous hack of re-trying with minimum width, which fails short when it splits strings. This inherits from `pprint.PrettyPrinter` to override `_format` in a minimal way to always dispatch, regardless of the given width. Code ref: https://github.com/python/cpython/blob/5c0c325453a175350e3c18ebb10cc10c37f9595c/Lib/pprint.py#L170-L178
Diffstat (limited to 'testing/test_assertion.py')
-rw-r--r--testing/test_assertion.py33
1 files changed, 27 insertions, 6 deletions
diff --git a/testing/test_assertion.py b/testing/test_assertion.py
index aac21a0df..6c700567a 100644
--- a/testing/test_assertion.py
+++ b/testing/test_assertion.py
@@ -462,6 +462,29 @@ class TestAssert_reprcompare:
" ]",
]
+ def test_list_dont_wrap_strings(self):
+ long_a = "a" * 10
+ l1 = ["a"] + [long_a for _ in range(0, 7)]
+ l2 = ["should not get wrapped"]
+ diff = callequal(l1, l2, verbose=True)
+ assert diff == [
+ "['a', 'aaaaaa...aaaaaaa', ...] == ['should not get wrapped']",
+ "At index 0 diff: 'a' != 'should not get wrapped'",
+ "Left contains 7 more items, first extra item: 'aaaaaaaaaa'",
+ "Full diff:",
+ " [",
+ "+ 'should not get wrapped',",
+ "- 'a',",
+ "- 'aaaaaaaaaa',",
+ "- 'aaaaaaaaaa',",
+ "- 'aaaaaaaaaa',",
+ "- 'aaaaaaaaaa',",
+ "- 'aaaaaaaaaa',",
+ "- 'aaaaaaaaaa',",
+ "- 'aaaaaaaaaa',",
+ " ]",
+ ]
+
def test_dict_wrap(self):
d1 = {"common": 1, "env": {"env1": 1}}
d2 = {"common": 1, "env": {"env1": 1, "env2": 2}}
@@ -479,22 +502,20 @@ class TestAssert_reprcompare:
]
long_a = "a" * 80
- sub = {"long_a": long_a, "sub1": {"long_a": "substring that gets wrapped"}}
+ sub = {"long_a": long_a, "sub1": {"long_a": "substring that gets wrapped " * 2}}
d1 = {"env": {"sub": sub}}
d2 = {"env": {"sub": sub}, "new": 1}
diff = callequal(d1, d2, verbose=True)
assert diff == [
- "{'env': {'sub...s wrapped'}}}} == {'env': {'sub...}}}, 'new': 1}",
+ "{'env': {'sub... wrapped '}}}} == {'env': {'sub...}}}, 'new': 1}",
"Omitting 1 identical items, use -vv to show",
"Right contains 1 more item:",
"{'new': 1}",
"Full diff:",
" {",
" 'env': {'sub': {'long_a': '" + long_a + "',",
- " 'sub1': {'long_a': 'substring '",
- " 'that '",
- " 'gets '",
- " 'wrapped'}}},",
+ " 'sub1': {'long_a': 'substring that gets wrapped substring '",
+ " 'that gets wrapped '}}},",
"+ 'new': 1,",
" }",
]