def getmsg(f, extra_ns=None, must_pass=False):
src = "<STR_LIT:\n>".join(_pytest._code.Code(f).source().lines)<EOL>mod = rewrite(src)<EOL>code = compile(mod, "<STR_LIT>", "<STR_LIT>")<EOL>ns = {}<EOL>if extra_ns is not None:<EOL><INDENT>ns.update(extra_ns)<EOL><DEDENT>six.exec_(code, ns)<EOL>func = ns[f.__name__]<EOL>try:<EOL><INDENT>func()<EOL><DEDENT>except AssertionError:<EOL><INDENT>if must_pass:<EOL><INDENT>pytest.fail("<STR_LIT>")<EOL><DEDENT>s = six.text_type(sys.exc_info()[<NUM_LIT:1>])<EOL>if not s.startswith("<STR_LIT>"):<EOL><INDENT>return "<STR_LIT>" + s<EOL><DEDENT>return s<EOL><DEDENT>else:<EOL><INDENT>if not must_pass:<EOL><INDENT>pytest.fail("<STR_LIT>")<EOL><DEDENT><DEDENT>
Rewrite the assertions in f, run it, and get the failure message.