Skip to content

Commit d1e00f6

Browse files
committed
Detect dynamic code explicitly in filter_traceback
1 parent 11f1008 commit d1e00f6

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

_pytest/python.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,14 @@ def _has_positional_arg(func):
4949

5050

5151
def filter_traceback(entry):
52-
# ensure entry.path is always a py.path.local object
52+
# entry.path might sometimes return a str() object when the entry
53+
# points to dynamically generated code
5354
# see https://bitbucket.org/pytest-dev/py/issues/71
54-
path = py.path.local(entry.path)
55-
return path != cutdir1 and not path.relto(cutdir2)
55+
raw_filename = entry.frame.code.raw.co_filename
56+
is_generated = '<' in raw_filename and '>' in raw_filename
57+
if is_generated:
58+
return False
59+
return entry.path != cutdir1 and not entry.path.relto(cutdir2)
5660

5761

5862
def get_real_func(obj):

testing/python/collect.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,7 @@ def test_filter_traceback_accepts_non_paths(self):
778778

779779
tb = py.code.Traceback(tb)
780780
assert isinstance(tb[-1].path, str) # symptom of the py.code bug
781-
assert filter_traceback(tb[-1])
781+
assert not filter_traceback(tb[-1])
782782

783783

784784
class TestReportInfo:

0 commit comments

Comments
 (0)