From d1e00f6e194741ba6e9ff1e662fe9145069211bd Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Wed, 30 Sep 2015 17:15:53 -0300 Subject: [PATCH] Detect dynamic code explicitly in filter_traceback --- _pytest/python.py | 10 +++++++--- testing/python/collect.py | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/_pytest/python.py b/_pytest/python.py index 8a1d04c6c..20e790530 100644 --- a/_pytest/python.py +++ b/_pytest/python.py @@ -49,10 +49,14 @@ def _has_positional_arg(func): def filter_traceback(entry): - # ensure entry.path is always a py.path.local object + # entry.path might sometimes return a str() object when the entry + # points to dynamically generated code # see https://bitbucket.org/pytest-dev/py/issues/71 - path = py.path.local(entry.path) - return path != cutdir1 and not path.relto(cutdir2) + raw_filename = entry.frame.code.raw.co_filename + is_generated = '<' in raw_filename and '>' in raw_filename + if is_generated: + return False + return entry.path != cutdir1 and not entry.path.relto(cutdir2) def get_real_func(obj): diff --git a/testing/python/collect.py b/testing/python/collect.py index e9178fb39..f660a8ab1 100644 --- a/testing/python/collect.py +++ b/testing/python/collect.py @@ -778,7 +778,7 @@ class TestTracebackCutting: tb = py.code.Traceback(tb) assert isinstance(tb[-1].path, str) # symptom of the py.code bug - assert filter_traceback(tb[-1]) + assert not filter_traceback(tb[-1]) class TestReportInfo: