Merge pull request #10673 from pytest-dev/backport-10660-to-7.2.x
[7.2.x] Derive pytest.raises from AbstractContextManager
This commit is contained in:
@@ -3,6 +3,11 @@
|
||||
This file is not executed, it is only checked by mypy to ensure that
|
||||
none of the code triggers any mypy errors.
|
||||
"""
|
||||
import contextlib
|
||||
from typing import Optional
|
||||
|
||||
from typing_extensions import assert_type
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
@@ -22,3 +27,9 @@ def check_fixture_ids_callable() -> None:
|
||||
@pytest.mark.parametrize("func", [str, int], ids=lambda x: str(x.__name__))
|
||||
def check_parametrize_ids_callable(func) -> None:
|
||||
pass
|
||||
|
||||
|
||||
def check_raises_is_a_context_manager(val: bool) -> None:
|
||||
with pytest.raises(RuntimeError) if val else contextlib.nullcontext() as excinfo:
|
||||
pass
|
||||
assert_type(excinfo, Optional[pytest.ExceptionInfo[RuntimeError]])
|
||||
|
||||
Reference in New Issue
Block a user