Coverage for tests/test_decorator.py: 100.00%
14 statements
« prev ^ index » next coverage.py v7.6.3, created at 2024-10-17 17:18 +0200
« prev ^ index » next coverage.py v7.6.3, created at 2024-10-17 17:18 +0200
1"""Tests for the `decorator` module."""
3from __future__ import annotations
5import inspect
7import pytest
9from duty.context import Context
10from duty.decorator import duty as decorate
11from duty.exceptions import DutyFailure
14def test_accept_one_posarg_when_decorating() -> None:
15 """Accept only one positional argument when decorating."""
16 with pytest.raises(ValueError, match="accepts only one positional argument"):
17 decorate(0, 1) # type: ignore[call-overload]
20def test_skipping() -> None:
21 """Wrap function that must be skipped."""
22 duty = decorate(lambda ctx: ctx.run("false"), skip_if=True) # type: ignore[call-overload]
23 # no DutyFailure raised
24 assert duty.run() is None
25 with pytest.raises(DutyFailure):
26 assert inspect.unwrap(duty)(Context({}))