Merge pull request #4451 from asottile/report_correct_filename_raises_exec

Fix `raises(..., "code(string)")` frame filename.
This commit is contained in:
Anthony Sottile 2018-11-23 17:29:09 -08:00 committed by GitHub
commit 860bc50772
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 1 deletions

View File

@ -0,0 +1 @@
Fix ``raises(..., 'code(string)')`` frame filename.

View File

@ -679,7 +679,7 @@ def raises(expected_exception, *args, **kwargs):
loc.update(kwargs)
# print "raises frame scope: %r" % frame.f_locals
try:
code = _pytest._code.Source(code).compile()
code = _pytest._code.Source(code).compile(_genframe=frame)
six.exec_(code, frame.f_globals, loc)
# XXX didn't mean f_globals == f_locals something special?
# this is destroyed here ...

View File

@ -17,6 +17,10 @@ class TestRaises(object):
def test_raises_exec(self):
pytest.raises(ValueError, "a,x = []")
def test_raises_exec_correct_filename(self):
excinfo = pytest.raises(ValueError, 'int("s")')
assert __file__ in excinfo.traceback[-1].path
def test_raises_syntax_error(self):
pytest.raises(SyntaxError, "qwe qwe qwe")