From 91aeaffff5093e75b2b5bdc5cedbdf4741febe7b Mon Sep 17 00:00:00 2001 From: eddiebergman Date: Mon, 21 Feb 2022 18:08:46 +0100 Subject: [PATCH 1/4] Doc: Add documentation for parametrize_all_cases and get_all_cases --- docs/api_reference.md | 8 +++++--- src/pytest_cases/case_parametrizer_new.py | 5 +++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/docs/api_reference.md b/docs/api_reference.md index 5d77d3dc..8076de65 100644 --- a/docs/api_reference.md +++ b/docs/api_reference.md @@ -257,8 +257,9 @@ 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, @@ -274,7 +275,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__cases.py` or if not found, `case_.py`, where `test_` 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 of 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. @@ -335,8 +336,9 @@ Note that you can get the same contents directly by using the [`current_cases`]( ### `get_all_cases` ```python +CaseType = Union[Callable, Type, ModuleRef] def get_all_cases(parametrization_target: Callable, - cases: Union[Callable, Type, ModuleRef] = None, + cases: Union[CaseType, List[CaseType]] = None, prefix: str = 'case_', glob: str = None, has_tag: Union[str, Iterable[str]] = None, diff --git a/src/pytest_cases/case_parametrizer_new.py b/src/pytest_cases/case_parametrizer_new.py index 2cd9e026..56618727 100644 --- a/src/pytest_cases/case_parametrizer_new.py +++ b/src/pytest_cases/case_parametrizer_new.py @@ -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 @@ -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 @@ -206,7 +207,7 @@ def _glob_name_filter(case_fun): def get_all_cases(parametrization_target, # 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]] From 4b2f77164068a7a9dd4472ff406c8b02d8c444a9 Mon Sep 17 00:00:00 2001 From: eddiebergman Date: Mon, 21 Feb 2022 18:11:57 +0100 Subject: [PATCH 2/4] Fix: typo --- docs/api_reference.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api_reference.md b/docs/api_reference.md index 8076de65..b51d4fc4 100644 --- a/docs/api_reference.md +++ b/docs/api_reference.md @@ -275,7 +275,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__cases.py` or if not found, `case_.py`, where `test_` 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 containing any mix of these elements. Note that both absolute and relative module names are supported. +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. From 6c21d53b157e9f44702056ee5dd7aa29bca8d6b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sylvain=20Mari=C3=A9?= Date: Tue, 22 Feb 2022 12:55:16 +0100 Subject: [PATCH 3/4] Update docs/api_reference.md --- docs/api_reference.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/api_reference.md b/docs/api_reference.md index b51d4fc4..89fb6ed8 100644 --- a/docs/api_reference.md +++ b/docs/api_reference.md @@ -258,6 +258,7 @@ CaseFilter(filter_function: Callable) ```python CaseType = Union[Callable, Type, ModuleRef] + @parametrize_with_cases(argnames: str, cases: Union[CaseType, List[CaseType]] = AUTO, prefix: str = 'case_', From 2d7a63c38885e3d285a39d58191dfa23dd9b9170 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sylvain=20Mari=C3=A9?= Date: Tue, 22 Feb 2022 12:55:21 +0100 Subject: [PATCH 4/4] Update docs/api_reference.md --- docs/api_reference.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/api_reference.md b/docs/api_reference.md index 89fb6ed8..e0d73200 100644 --- a/docs/api_reference.md +++ b/docs/api_reference.md @@ -338,6 +338,7 @@ Note that you can get the same contents directly by using the [`current_cases`]( ```python CaseType = Union[Callable, Type, ModuleRef] + def get_all_cases(parametrization_target: Callable, cases: Union[CaseType, List[CaseType]] = None, prefix: str = 'case_',