You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
|`between(b, a, c, msg="", ge=False, le=False)`|`a < b < c`||
89
+
|`between_equal(b, a, c, msg="")`|`a <= b <= c`| same as `between(b, a, c, msg, ge=True, le=True)`|
90
+
|`raises(expected_exception, *args, **kwargs)`|*Raises given exception*| similar to [pytest.raises](https://docs.pytest.org/en/latest/reference/reference.html#pytest-raises)|
91
+
|`fail(msg)`|*Log a failure*||
92
+
93
+
**Note: This is a list of relatively common logic operators. I'm reluctant to add to the list too much, as it's easy to add your own.**
94
+
90
95
91
96
The httpx example can be rewritten with helper functions:
92
97
@@ -103,8 +108,9 @@ Which you use is personal preference.
103
108
104
109
## Defining your own check functions
105
110
106
-
The `@check.check_func` decorator allows you to wrap any test helper that has an assert
107
-
statement in it to be a non-blocking assert function.
111
+
### Using `@check.check_func`
112
+
113
+
The `@check.check_func` decorator allows you to wrap any test helper that has an assert statement in it to be a non-blocking assert function.
108
114
109
115
110
116
```python
@@ -121,6 +127,33 @@ def test_all_four():
121
127
is_four(4)
122
128
```
123
129
130
+
131
+
### Using `check.fail()`
132
+
133
+
Using `@check.check_func` is probably the easiest.
134
+
However, it does have a bit of overhead in the passing cases
135
+
that can affect large loops of checks.
136
+
137
+
If you need a bit of a speedup, use the following style with the help of `check.fail()`.
138
+
139
+
```python
140
+
from pytest_check import check
141
+
142
+
defis_four(a):
143
+
__tracebackhide__ =True
144
+
if a ==4:
145
+
returnTrue
146
+
else:
147
+
check.fail(f"check {a} == 4")
148
+
returnFalse
149
+
150
+
deftest_all_four():
151
+
is_four(1)
152
+
is_four(2)
153
+
is_four(3)
154
+
is_four(4)
155
+
```
156
+
124
157
## Using raises as a context manager
125
158
126
159
`raises` is used as context manager, much like `pytest.raises`. The main difference being that a failure to raise the right exception won't stop the execution of the test method.
0 commit comments