Skip to content

Commit

Permalink
Doc: Add documentation for parametrize_all_cases and get_all_cases (#259
Browse files Browse the repository at this point in the history
)

* Doc: Add documentation for parametrize_all_cases and get_all_cases

* Fix: typo

* Update docs/api_reference.md

* Update docs/api_reference.md

Co-authored-by: Sylvain Marié <sylvain.marie@schneider-electric.com>
  • Loading branch information
eddiebergman and smarie committed Mar 21, 2022
1 parent e960630 commit 05d7998
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
12 changes: 8 additions & 4 deletions docs/api_reference.md
Expand Up @@ -257,8 +257,10 @@ CaseFilter(filter_function: Callable)
### `@parametrize_with_cases`

```python
CaseType = Union[Callable, Type, ModuleRef]

@parametrize_with_cases(argnames: str,
cases: Union[Callable, Type, ModuleRef] = AUTO,
cases: Union[CaseType, List[CaseType]] = AUTO,
prefix: str = 'case_',
glob: str = None,
has_tag: Union[str, Iterable[str]] = None,
Expand All @@ -274,7 +276,7 @@ A decorator for test functions or fixtures, to parametrize them based on test ca

By default (`cases=AUTO`) the list of test cases is automatically drawn from the python module file named `test_<name>_cases.py` or if not found, `case_<name>.py`, where `test_<name>` is the current module name.

Finally, the `cases` argument also accepts an explicit case function, cases-containing class, module or module name; or a list of such elements. Note that both absolute and relative module names are suported.
Finally, the `cases` argument also accepts an explicit case function, cases-containing class, module or module name; or a list containing any mix of these elements. Note that both absolute and relative module names are supported.

Note that `@parametrize_with_cases` collection and parameter creation steps are strictly equivalent to [`get_all_cases`](#get_all_cases) + [`get_parametrize_args`](#get_parametrize_args). This can be handy for debugging purposes.

Expand Down Expand Up @@ -335,8 +337,10 @@ Note that you can get the same contents directly by using the [`current_cases`](
### `get_all_cases`

```python
def get_all_cases(parametrization_target: Callable = None,
cases: Union[Callable, Type, ModuleRef] = None,
CaseType = Union[Callable, Type, ModuleRef]

def get_all_cases(parametrization_target: Callable,
cases: Union[CaseType, List[CaseType]] = None,
prefix: str = 'case_',
glob: str = None,
has_tag: Union[str, Iterable[str]] = None,
Expand Down
5 changes: 3 additions & 2 deletions src/pytest_cases/case_parametrizer_new.py
Expand Up @@ -56,6 +56,7 @@
from types import ModuleType # noqa

ModuleRef = Union[str, ModuleType, Literal[AUTO], Literal[THIS_MODULE]] # noqa
CaseType = Union[Callable, Type, ModuleRef]

except: # noqa
pass
Expand All @@ -65,7 +66,7 @@


def parametrize_with_cases(argnames, # type: Union[str, List[str], Tuple[str, ...]]
cases=AUTO, # type: Union[Callable, Type, ModuleRef]
cases=AUTO, # type: Union[CaseType, List[CaseType]]
prefix=CASE_PREFIX_FUN, # type: str
glob=None, # type: str
has_tag=None, # type: Any
Expand Down Expand Up @@ -206,7 +207,7 @@ def _glob_name_filter(case_fun):


def get_all_cases(parametrization_target=None, # type: Callable
cases=None, # type: Union[Callable, Type, ModuleRef]
cases=None, # type: Union[CaseType, List[CaseType]]
prefix=CASE_PREFIX_FUN, # type: str
glob=None, # type: str
has_tag=None, # type: Union[str, Iterable[str]]
Expand Down

0 comments on commit 05d7998

Please sign in to comment.