Bug
The function \is_fully_escaped\ in \src/_pytest/raises.py\ only checks whether the character immediately before a regex metacharacter is a backslash. It does not count how many consecutive backslashes precede the metacharacter.
When two backslashes appear before a metacharacter (e.g.
'\\.'), the first backslash escapes the second, so the metacharacter is left unescaped. But \is_fully_escaped\ sees a backslash before the dot and incorrectly reports the string as fully escaped.
Impact
This affects \pytest.raises(match=...)\ when the match pattern contains escaped backslashes followed by a regex metacharacter. The match failure message may skip showing a regex diff and instead show a less helpful message.
Reproduction
\\python
from _pytest.raises import is_fully_escaped
Should be False: two backslashes escape each other, leaving . unescaped
is_fully_escaped(r'\\.') # Returns True (wrong)
Should be False: four backslashes = two escaped pairs, | unescaped
is_fully_escaped('\\\\|') # Returns True (wrong)
\\
Expected behavior
Count consecutive backslashes. If the count is even, the metacharacter is not escaped. If odd, it is escaped.
Bug
The function \is_fully_escaped\ in \src/_pytest/raises.py\ only checks whether the character immediately before a regex metacharacter is a backslash. It does not count how many consecutive backslashes precede the metacharacter.
When two backslashes appear before a metacharacter (e.g.
'\\.'), the first backslash escapes the second, so the metacharacter is left unescaped. But \is_fully_escaped\ sees a backslash before the dot and incorrectly reports the string as fully escaped.
Impact
This affects \pytest.raises(match=...)\ when the match pattern contains escaped backslashes followed by a regex metacharacter. The match failure message may skip showing a regex diff and instead show a less helpful message.
Reproduction
\\python
from _pytest.raises import is_fully_escaped
Should be False: two backslashes escape each other, leaving . unescaped
is_fully_escaped(r'\\.') # Returns True (wrong)
Should be False: four backslashes = two escaped pairs, | unescaped
is_fully_escaped('\\\\|') # Returns True (wrong)
\\
Expected behavior
Count consecutive backslashes. If the count is even, the metacharacter is not escaped. If odd, it is escaped.