-2

I have a case where I need to match a multi-line message, and I want to check it, via a multiline regexp match. I fail. See sample code, when I try to match a text which exists in two lines:

def foo(): #always raises, has two lines
   raise ValueError( "Moo\nMah\n" )
with pytest.raises(  ValueError, match= r'Mo.*Ma' ):
    foo()
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
File "<stdin>", line 2, in foo
ValueError: Moo
Mah

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "<stdin>", line 2, in <module>
File "/home/foo/.local/lib/python3.8/site-packages/_pytest/python_api.py", line 975,
in __exit__
self.excinfo.match(self.match_expr)
File "/home/foo/.local/lib/python3.8/site-packages/_pytest/_code/code.py", line 678, in match
assert re.search(regexp, str(self.value)), msg.format(regexp, str(self.value))
AssertionError: Regex pattern 'Mo.*Ma' does not match 'Moo\nMah\n'.

What do I do, to get the Regex pattern to match?

user1134991
  • 2,885
  • 2
  • 20
  • 30

0 Answers0