-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add option to skip duties based on condition
- Loading branch information
Showing
4 changed files
with
57 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,24 @@ | ||
"""Tests for the `decorator` module.""" | ||
|
||
import inspect | ||
|
||
import pytest | ||
|
||
from duty.context import Context | ||
from duty.decorator import duty as decorate | ||
from duty.exceptions import DutyFailure | ||
|
||
|
||
def test_accept_one_posarg_when_decorating(): | ||
"""Accept only one positional argument when decorating.""" | ||
with pytest.raises(ValueError, match="accepts only one positional argument"): | ||
decorate(0, 1) | ||
|
||
|
||
def test_skipping(): | ||
"""Wrap function that must be skipped.""" | ||
duty = decorate(lambda ctx: ctx.run("false"), skip_if=True) | ||
# no DutyFailure raised | ||
assert duty.run() is None | ||
with pytest.raises(DutyFailure): | ||
assert inspect.unwrap(duty)(Context({})) |