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
Copy file name to clipboardExpand all lines: docs/api_reference.md
+55Lines changed: 55 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -178,6 +178,61 @@ Returns True if the provided object is a function or callable and, if `check_pre
178
178
179
179
-`check_prefix`: if this boolean is True (default), the prefix will be checked. If False, any function will lead to a `True` result whatever its name.
180
180
181
+
### The `filters` submodule
182
+
183
+
This submodule contains symbols to help you create filters for `@parametrize_with_cases(filter=...)`.
184
+
185
+
All helper filters in this submodule return an instance of `CaseFilter`, so that you can combine them easily with "and" (`&`) "or" (`|`) and "invert" (`~`) in order to create new custom filters.
186
+
187
+
#### `has_tag`
188
+
189
+
```python
190
+
defhas_tag(tag_name: str)
191
+
```
192
+
193
+
Selects cases that have the tag `tag_name`. See `@case(tags=...)` to add tags to a case.
194
+
195
+
#### `has_tags`
196
+
197
+
```python
198
+
defhas_tags(*tag_names: str)
199
+
```
200
+
201
+
Selects cases that have all tags `tag_names`. See `@case(tags=...)` to add tags to a case.
202
+
203
+
#### `id_has_prefix`
204
+
205
+
```python
206
+
defid_has_prefix(prefix: str)
207
+
```
208
+
209
+
Selects cases that have a case id prefix `prefix`. Note that this is not the prefix of the whole case function name, but the case id, possibly overridden with `@case(id=)`
210
+
211
+
#### `id_has_suffix`
212
+
213
+
```python
214
+
defid_has_suffix(suffix: str)
215
+
```
216
+
217
+
Selects cases that have a case id suffix `suffix`. Note that this is not the suffix of the whole case function name, but the case id, possibly overridden with `@case(id=)`
218
+
219
+
220
+
#### `id_match_regex`
221
+
222
+
```python
223
+
defid_match_regex(regex: str)
224
+
```
225
+
226
+
Selects cases that have a case id matching regex pattern `regex`. Note that this is not a match of the whole case function name, but the case id, possibly overridden with `@case(id=)`
227
+
228
+
#### `CaseFilter`
229
+
230
+
```python
231
+
CaseFilter(filter_function: Callable)
232
+
```
233
+
234
+
`CaseFilter` is the class used by all filters above, and implementing logical operations "and" (`&`) "or" (`|`) and "not" (`~`). You can use it to define a composable filter from any callable receiving a single `case` argument and returning a boolean indicating if the `case` is selected.
Copy file name to clipboardExpand all lines: docs/index.md
+5-6Lines changed: 5 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -292,20 +292,19 @@ def test_foo(a):
292
292
@parametrize_with_cases("data", cases='.',
293
293
filter=lambdacf: "success"in cf._pytestcase.id)
294
294
deftest_good_datasets2(data):
295
-
assert sqrt(data) >0
295
+
...
296
296
```
297
297
298
-
-pytest-cases offers you an array of default filter for you to choose from in the `filters` module such as: `has_tag`, `has_prefix`, and etc. You can use logical operations on them like "and" (&) "or" (|) and "invert" (~) in order to create you own custom filters.
298
+
-An array of default filters is available in the `filters` module: `has_tag`, `id_has_prefix`, etc. You can use logical operations on them such as "and" (`&`) "or" (`|`) and "not" (`~`) in order to create your own custom filters. See [API reference](./api_reference.md#the-filters-submodule) for details.
0 commit comments