(pytester: Pytester, type: str)
| 375 | |
| 376 | @pytest.mark.parametrize("type", ["Error", "Failure"]) |
| 377 | def test_testcase_custom_exception_info(pytester: Pytester, type: str) -> None: |
| 378 | pytester.makepyfile( |
| 379 | """ |
| 380 | from typing import Generic, TypeVar |
| 381 | from unittest import TestCase |
| 382 | import pytest, _pytest._code |
| 383 | |
| 384 | class MyTestCase(TestCase): |
| 385 | def run(self, result): |
| 386 | excinfo = pytest.raises(ZeroDivisionError, lambda: 0/0) |
| 387 | # We fake an incompatible exception info. |
| 388 | class FakeExceptionInfo(Generic[TypeVar("E")]): |
| 389 | def __init__(self, *args, **kwargs): |
| 390 | mp.undo() |
| 391 | raise TypeError() |
| 392 | @classmethod |
| 393 | def from_current(cls): |
| 394 | return cls() |
| 395 | @classmethod |
| 396 | def from_exc_info(cls, *args, **kwargs): |
| 397 | return cls() |
| 398 | mp = pytest.MonkeyPatch() |
| 399 | mp.setattr(_pytest._code, 'ExceptionInfo', FakeExceptionInfo) |
| 400 | try: |
| 401 | excinfo = excinfo._excinfo |
| 402 | result.add%(type)s(self, excinfo) |
| 403 | finally: |
| 404 | mp.undo() |
| 405 | |
| 406 | def test_hello(self): |
| 407 | pass |
| 408 | """ |
| 409 | % locals() |
| 410 | ) |
| 411 | result = pytester.runpytest() |
| 412 | result.stdout.fnmatch_lines( |
| 413 | [ |
| 414 | "NOTE: Incompatible Exception Representation*", |
| 415 | "*ZeroDivisionError*", |
| 416 | "*1 failed*", |
| 417 | ] |
| 418 | ) |
| 419 | |
| 420 | |
| 421 | def test_testcase_totally_incompatible_exception_info(pytester: Pytester) -> None: |
nothing calls this directly
no test coverage detected