blob: 820210ce9a48bd7c41ce1d8dd6bf0c1e9a3d88e7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# -*- coding: utf-8 -*-
from __future__ import absolute_import
import sys
import pytest
from gi._compat import reraise
@pytest.hookimpl(hookwrapper=True, tryfirst=True)
def pytest_runtest_call(item):
"""A pytest hook which takes over sys.excepthook and raises any uncaught
exception (with PyGObject this happesn often when we get called from C,
like any signal handler, vfuncs tc)
"""
exceptions = []
def on_hook(type_, value, tback):
exceptions.append((type_, value, tback))
orig_excepthook = sys.excepthook
sys.excepthook = on_hook
try:
yield
finally:
sys.excepthook = orig_excepthook
if exceptions:
reraise(*exceptions[0])
|