And, of course, most of the time, stderr will come as a part of an exception, so try/except has to be used in such
a case:
thon
def raise_exception(msg):
    raise ValueError(msg)
def test_something_exception():
    msg = "Not a good value"
    error = ""
    try:
        raise_exception(msg)
    except Exception as e:
        error = str(e)
        assert msg in error, f"{msg} is in the exception:\n{error}"