|
1 | 1 | """pytest-trio implementation.""" |
| 2 | +import sys |
2 | 3 | from functools import wraps, partial |
3 | | -from traceback import format_exception |
4 | 4 | from collections.abc import Coroutine, Generator |
5 | 5 | from contextlib import asynccontextmanager |
6 | 6 | from inspect import isasyncgen, isasyncgenfunction, iscoroutinefunction |
|
11 | 11 | from trio.abc import Clock, Instrument |
12 | 12 | from trio.testing import MockClock |
13 | 13 |
|
| 14 | +if sys.version_info[:2] < (3, 11): |
| 15 | + from exceptiongroup import BaseExceptionGroup |
| 16 | + |
14 | 17 | ################################################################ |
15 | 18 | # Basic setup |
16 | 19 | ################################################################ |
@@ -52,13 +55,6 @@ def pytest_configure(config): |
52 | 55 | ) |
53 | 56 |
|
54 | 57 |
|
55 | | -@pytest.hookimpl(tryfirst=True) |
56 | | -def pytest_exception_interact(node, call, report): |
57 | | - if issubclass(call.excinfo.type, trio.MultiError): |
58 | | - # TODO: not really elegant (pytest cannot output color with this hack) |
59 | | - report.longrepr = "".join(format_exception(*call.excinfo._excinfo)) |
60 | | - |
61 | | - |
62 | 58 | ################################################################ |
63 | 59 | # Core support for trio fixtures and trio tests |
64 | 60 | ################################################################ |
@@ -407,8 +403,12 @@ async def _bootstrap_fixtures_and_run_test(**kwargs): |
407 | 403 | ) |
408 | 404 | ) |
409 | 405 |
|
410 | | - if test_ctx.error_list: |
411 | | - raise trio.MultiError(test_ctx.error_list) |
| 406 | + if len(test_ctx.error_list) == 1: |
| 407 | + raise test_ctx.error_list[0] |
| 408 | + elif test_ctx.error_list: |
| 409 | + raise BaseExceptionGroup( |
| 410 | + "errors in async test and trio fixtures", test_ctx.error_list |
| 411 | + ) |
412 | 412 |
|
413 | 413 | _bootstrap_fixtures_and_run_test._trio_test_runner_wrapped = True |
414 | 414 | return _bootstrap_fixtures_and_run_test |
|
0 commit comments