@@ -56,6 +56,12 @@ def pytest_addoption(parser):
56
56
action = "store_true" ,
57
57
help = "pytest-icdiff: strip any trailing carriage return at the end of an input line" ,
58
58
)
59
+ parser .addoption (
60
+ "--icdiff-multiline-string" ,
61
+ default = False ,
62
+ action = "store_true" ,
63
+ help = "pytest-icdiff: proper differences for multiline strings" ,
64
+ )
59
65
60
66
61
67
def pytest_assertrepr_compare (config , op , left , right ):
@@ -76,8 +82,16 @@ def pytest_assertrepr_compare(config, op, left, right):
76
82
half_cols = COLS / 2 - MARGINS
77
83
TABSIZE = int (config .getoption ("--icdiff-tabsize" ) or 2 )
78
84
79
- pretty_left = pformat (left , indent = TABSIZE , width = half_cols ).splitlines ()
80
- pretty_right = pformat (right , indent = TABSIZE , width = half_cols ).splitlines ()
85
+ if (
86
+ config .getoption ("--icdiff-multiline-string" )
87
+ and isinstance (left , str )
88
+ and isinstance (right , str )
89
+ ):
90
+ pretty_left = left .splitlines ()
91
+ pretty_right = right .splitlines ()
92
+ else :
93
+ pretty_left = pformat (left , indent = TABSIZE , width = half_cols ).splitlines ()
94
+ pretty_right = pformat (right , indent = TABSIZE , width = half_cols ).splitlines ()
81
95
diff_cols = COLS - MARGINS
82
96
83
97
if len (pretty_left ) < 3 or len (pretty_right ) < 3 :
0 commit comments