The match argument to pytest.raises and pytest.warns is a regular expression applied with re.search against str(exception). Two consequences follow. It matches anywhere in the message, not the whole string, so a short pattern passes against a longer message. And characters such as (, ), [, ., + and ? are regex syntax, so a literal message containing them either fails to match or raises a regex compilation error.
A message like invalid value (got 3) needs re.escape("invalid value (got 3)"), which is the reliable general form when you want a literal comparison.
When the match fails, pytest reports DID NOT MATCH along with both the pattern and the actual message, which usually makes the cause obvious. For anchoring, add ^ and $ explicitly. And remember that str() of an exception with multiple args includes the tuple repr, so a raise with two arguments produces a message that does not look like either of them; check with a quick repr(str(exc)) before writing the pattern.