def test_render_can_ignore_given_files(): import os from .helpers import outer io = BufferedIO() io.set_verbosity(VERBOSE) def call(): def run(): outer() run() with pytest.raises(Exception) as e: call() trace = ExceptionTrace(e.value) helpers_file = os.path.join(os.path.dirname(__file__), "helpers.py") trace.ignore_files_in("^{}$".format(re.escape(helpers_file))) trace.render(io) expected = """ Stack trace: 2 {}:297 in test_render_can_ignore_given_files call() 1 {}:294 in call run() Exception Foo at {}:3 in inner 1│ def outer(): 2│ def inner(): → 3│ raise Exception("Foo") 4│ 5│ inner() 6│ """.format( trace._get_relative_file_path(__file__), trace._get_relative_file_path(__file__), trace._get_relative_file_path(helpers_file), ) assert expected == io.fetch_output()
def test_render_shows_ignored_files_if_in_debug_mode(): import os from .helpers import outer io = BufferedIO() io.set_verbosity(DEBUG) def call(): def run(): outer() run() with pytest.raises(Exception) as e: call() trace = ExceptionTrace(e.value) helpers_file = os.path.join(os.path.dirname(__file__), "helpers.py") trace.ignore_files_in("^{}$".format(re.escape(helpers_file))) trace.render(io) expected = """ Stack trace: 4 {}:352 in test_render_shows_ignored_files_if_in_debug_mode 350│ 351│ with pytest.raises(Exception) as e: → 352│ call() 353│ 354│ trace = ExceptionTrace(e.value) 3 {}:349 in call 347│ outer() 348│ → 349│ run() 350│ 351│ with pytest.raises(Exception) as e: 2 {}:347 in run 345│ def call(): 346│ def run(): → 347│ outer() 348│ 349│ run() 1 {}:5 in outer 3│ raise Exception("Foo") 4│ → 5│ inner() 6│ Exception Foo at {}:3 in inner 1│ def outer(): 2│ def inner(): → 3│ raise Exception("Foo") 4│ 5│ inner() 6│ """.format( trace._get_relative_file_path(__file__), trace._get_relative_file_path(__file__), trace._get_relative_file_path(__file__), trace._get_relative_file_path(helpers_file), trace._get_relative_file_path(helpers_file), ) assert expected == io.fetch_output()