Fix typing of expect_failure()
TODO: put _XfailMarkDecorator fix into its own pull request TODO: squash into previous commit
This commit is contained in:
parent
8c4ca32f8d
commit
d510bbe832
|
@ -426,7 +426,9 @@ if TYPE_CHECKING:
|
||||||
*conditions: Union[str, bool],
|
*conditions: Union[str, bool],
|
||||||
reason: str = ...,
|
reason: str = ...,
|
||||||
run: bool = ...,
|
run: bool = ...,
|
||||||
raises: Union[Type[BaseException], Tuple[Type[BaseException], ...]] = ...,
|
raises: Optional[
|
||||||
|
Union[Type[BaseException], Tuple[Type[BaseException], ...]]
|
||||||
|
] = ...,
|
||||||
strict: bool = ...,
|
strict: bool = ...,
|
||||||
) -> MarkDecorator:
|
) -> MarkDecorator:
|
||||||
...
|
...
|
||||||
|
|
|
@ -6,6 +6,7 @@ import traceback
|
||||||
from collections.abc import Mapping
|
from collections.abc import Mapping
|
||||||
from contextvars import ContextVar
|
from contextvars import ContextVar
|
||||||
from typing import Generator
|
from typing import Generator
|
||||||
|
from typing import MutableMapping
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
from typing import Tuple
|
from typing import Tuple
|
||||||
from typing import Type
|
from typing import Type
|
||||||
|
@ -306,19 +307,23 @@ def pytest_runtest_protocol(item: Item, nextitem: Optional[Item]) -> None:
|
||||||
current_item_var.set(item)
|
current_item_var.set(item)
|
||||||
|
|
||||||
|
|
||||||
_not_passed = object()
|
class _NotPassed:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
_not_passed = _NotPassed()
|
||||||
|
|
||||||
|
|
||||||
def expect_failure(
|
def expect_failure(
|
||||||
reason: str = _not_passed,
|
reason: str = "",
|
||||||
raises: Union[Type[BaseException], Tuple[Type[BaseException], ...]] = _not_passed,
|
raises: Optional[
|
||||||
strict: bool = _not_passed,
|
Union[Type[BaseException], Tuple[Type[BaseException], ...]]
|
||||||
|
] = None,
|
||||||
|
strict: Union[bool, _NotPassed] = _not_passed,
|
||||||
) -> None:
|
) -> None:
|
||||||
kwargs = {}
|
kwargs: MutableMapping[str, bool] = {}
|
||||||
if reason is not _not_passed:
|
if not isinstance(strict, _NotPassed):
|
||||||
kwargs["reason"] = reason
|
|
||||||
if raises is not _not_passed:
|
|
||||||
kwargs["raises"] = raises
|
|
||||||
if strict is not _not_passed:
|
|
||||||
kwargs["strict"] = strict
|
kwargs["strict"] = strict
|
||||||
current_item_var.get().add_marker(MARK_GEN.xfail(**kwargs))
|
current_item_var.get().add_marker(
|
||||||
|
MARK_GEN.xfail(reason=reason, raises=raises, **kwargs)
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in New Issue