Skip to content

Commit

Permalink
add test for traceback frame removal
Browse files Browse the repository at this point in the history
  • Loading branch information
belm0 committed Aug 25, 2018
1 parent 203860c commit a150e77
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions trio/_core/tests/test_run.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import contextvars
import functools
import platform
import re
import sys
import threading
import time
import traceback
import warnings
from contextlib import contextmanager
from math import inf
Expand Down Expand Up @@ -1897,6 +1899,27 @@ def handle(exc):
assert result == [[0, 0], [1, 1]]


async def test_run_impl_traceback_frame_removal():
async def my_child_task():
raise KeyError()

try:
# Trick: For now cancel/nursery scopes still leave a bunch of tb gunk
# behind. But if there's a MultiError, they leave it on the MultiError,
# which lets us get a clean look at the KeyError itself. Someday I
# guess this will always be a MultiError (#611), but for now we can
# force it by raising two exceptions.
async with _core.open_nursery() as nursery:
nursery.start_soon(my_child_task)
nursery.start_soon(my_child_task)
except _core.MultiError as exc:
first_exc = exc.exceptions[0]
assert isinstance(first_exc, KeyError)
tb_text = ''.join(traceback.format_tb(first_exc.__traceback__))
for r in ('/trio/_core/.* in run_impl$', '/contextvars/.* in run$'):
assert not re.search(r, tb_text, re.MULTILINE)


def test_contextvar_support():
var = contextvars.ContextVar("test")
var.set("before")
Expand Down

0 comments on commit a150e77

Please sign in to comment.