Skip to content

Commit eba5abc

Browse files
committed
a little helper to strip color codes
1 parent 2ef4dd9 commit eba5abc

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

tests/test_pytest_icdiff.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@ def test_thing():
163163
_assert_line_in_ignoring_whitespace(expected[0], output)
164164

165165

166+
def strip_color_codes(s):
167+
return re.sub(r'\x1b\[[0-9;]*m', '', s)
168+
166169

167170
def test_avoids_single_line_diffs(testdir):
168171
one = {1: "1", 2: "2"}
@@ -175,7 +178,7 @@ def test_one():
175178
)
176179
output = testdir.runpytest('-vv').stdout.str()
177180
print(repr(output))
178-
assert re.search(r"1: '1',\s+$", output, flags=re.MULTILINE)
181+
assert "1: '1', 1: '1'," in strip_color_codes(output)
179182

180183

181184
def test_does_not_break_drilldown_for_int_comparison(testdir):
@@ -203,6 +206,7 @@ def test_one():
203206
comparison_line = next(l for l in output.splitlines() if '1:' in l and "assert" not in l)
204207
assert comparison_line.count('hell') < 13
205208

209+
206210
def test_long_lines_in_comparators_are_wrapped_sensibly_singleline(testdir):
207211
left = "hello " * 10
208212
right = "hella " * 10
@@ -272,4 +276,3 @@ def test_one():
272276
)
273277
output = testdir.runpytest('-vv', '--color=yes').stdout.str()
274278
assert f"123456 123456{GREEN_ON}7" in output
275-

0 commit comments

Comments
 (0)