diff --git a/testbase/util.py b/testbase/util.py index d5b417e..d773dbc 100644 --- a/testbase/util.py +++ b/testbase/util.py @@ -611,9 +611,17 @@ def get_method_defined_class(method): def get_last_frame_stack(back_count=2): + from testbase.conf import settings + filter_funcs = [] + if hasattr(settings, "QTAF_STACK_FILTERS"): + filter_funcs = settings.QTAF_STACK_FILTERS frame = inspect.currentframe() - for _ in range(back_count): + i = 0 + while i < back_count: frame = frame.f_back + if frame.f_code.co_name in filter_funcs: + continue + i += 1 stack = "".join(traceback.format_stack(frame, 1)) return stack diff --git a/tests/test_testbase/test_util.py b/tests/test_testbase/test_util.py index 448c142..99e02d6 100644 --- a/tests/test_testbase/test_util.py +++ b/tests/test_testbase/test_util.py @@ -23,6 +23,7 @@ import six from testbase import util +from testbase.test import modify_settings class UtilTest(unittest.TestCase): @@ -84,3 +85,12 @@ def lock_thread(): time_cost = time.time() - time0 self.assertGreater(time_cost, timeout + 1) self.assertLess(time_cost, timeout + 1.5) + + def test_get_last_frame_stack(self): + def func_wrapper(): + return util.get_last_frame_stack(2) + stack = func_wrapper() + assert "func_wrapper" in stack + with modify_settings(QTAF_STACK_FILTERS=["func_wrapper"]): + stack = func_wrapper() + assert "func_wrapper" not in stack