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/index.md
+15-10Lines changed: 15 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -488,10 +488,11 @@ In some scenarii you may wish to access the case functions that are currently us
488
488
With `pytest-cases` starting in version `3.5`, this is now possible thanks to the `current_cases` fixture. Simply use this fixture to get a dictionary containing the actual parameter idand case function forall parameters parametrized with cases in the current test node. Parametrized fixtures, ifany, will appear in a sub-dictionary indexed by the fixture name.
489
489
490
490
```python
491
-
from pytest_cases import parametrize_with_cases, fixture
491
+
from pytest_cases importparametrize, parametrize_with_cases, fixture
# let's print all case information for this test node
511
512
print(current_cases)
512
513
```
513
514
514
515
yields
515
516
516
517
```
517
-
{'data': ('a', <function case_a at 0x00000205BED1CF28>),
518
-
'my_fixture': {'foo': ('a', <function case_a at 0x00000205BED1CF28>)}}
518
+
{'data': Case(id='a', func=<function case_a at 0x000001C0CAE9E700>, params={'nb': 1}),
519
+
'my_fixture': {
520
+
'foo': Case(id='a', func=<function case_a at 0x000001C0CAE9E700>, params={'nb': 1})
521
+
}}
519
522
```
520
523
521
-
To get more information on the case function, you can use `get_case_id(f)`, `get_case_marks(f)`, `get_case_tags(f)`. You can also use `matches_tag_query` to check if a case function matches some expectations either concerning its idor its tags. See [API reference](./api_reference.md#matches_tag_query).
524
+
As you can see above, details are provided as`namedtuple`s. When a case itself is parametrized, its current parameter value(s) appear too (in the above example, `case_a`is parametrized with`nb`).
525
+
526
+
To get more information on the case function, you can use `get_case_marks(func)`, `get_case_tags(func)`. You can also use `matches_tag_query(...)` to check if a case function matches some expectations either concerning its idor its tags. See [API reference](./api_reference.md#matches_tag_query).
522
527
523
528
Note: you can get the same information from a pytest hook, using the `get_current_cases` function. See [API reference](./api_reference.md#get_current_cases) for details.
0 commit comments