This doctest fails with an output shown at the bottom. Why does Pytest change the doctest to strip_special_chars( "c:\abcDEF1 [email protected]") with a single backslash leading to the unintended expected result? How do I change its behavior?
def strip_special_chars(input_text, re_string='[^a-zA-Z0-9_\s\.\-:\\\\]'):
"""
>>> strip_special_chars( "c:\\abcDEF1 [email protected]")
'c:\\abcDEF1 23-_.sql'
"""
regex = re.compile(re_string)
return regex.sub('', input_text)
_____________________________________________ [doctest] helpers.strip_special_chars _____________________________________________
1484
1485 >>> strip_special_chars( "c:\abcDEF1 [email protected]")
Expected:
'c:\abcDEF1 23-_.sql'
Got:
'c:bcDEF1 23-_.sql'
Adding
rto the doctest string fixed it. Because the argument ("c:\abcDEF1 [email protected]") is inside """, it appears that\\changes to\(thereby having no escaping) before Pytest sees it.