Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ jobs:

# Share ./docs/reports so that they can be deployed with doc in next job
- name: Share reports with other jobs
# if: matrix.nox_session == '...': not needed, if empty wont be shared
# if: matrix.nox_session == '...': not needed, if empty won't be shared
uses: actions/upload-artifact@master
with:
name: reports_dir
Expand Down
14 changes: 7 additions & 7 deletions docs/api_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ cases = get_all_cases(f, cases=".")
import test.test_xyz
xyz_cases = get_all_cases(test.test_xyz)

# Can be used to filter explict cases, in which case no parametrization_target is needed
# Can be used to filter explicit cases, in which case no parametrization_target is needed
filtered_cases = get_all_cases(cases=[case_1, case_2, case_3], has_tag=["banana"])
```

Expand Down Expand Up @@ -413,7 +413,7 @@ As a consequence it does not support the `params` and `ids` arguments anymore.
- **autouse**: if True, the fixture func is activated for all tests that can see it. If False (the default) then an explicitreference is needed to activate the fixture.
- **name**: the name of the fixture. This defaults to the name of the decorated function. Note: If a fixture is used in the same module in which it is defined, the function name of the fixture will be shadowed by the function arg that requests the fixture; one wayto resolve this is to name the decorated function ``fixture_<fixturename>`` and then use ``@pytest.fixture(name='<fixturename>')``.
- **unpack_into**: an optional iterable of names, or string containing coma-separated names, for additional fixtures to create to represent parts of this fixture. See [`unpack_fixture`](#unpack_fixture) for details.
- **hook**: an optional hook to apply to each fixture function that is created during this call. The hook function will be called everytime a fixture is about to be created. It will receive a single argument (the function implementing the fixture) and should return the function to use. For example you can use `saved_fixture` from `pytest-harvest` as a hook in order to save all such created fixtures in the fixture store.
- **hook**: an optional hook to apply to each fixture function that is created during this call. The hook function will be called every time a fixture is about to be created. It will receive a single argument (the function implementing the fixture) and should return the function to use. For example you can use `saved_fixture` from `pytest-harvest` as a hook in order to save all such created fixtures in the fixture store.
- **kwargs**: other keyword arguments for `@pytest.fixture`

### `unpack_fixture`
Expand Down Expand Up @@ -468,7 +468,7 @@ class TestClass:
- **argnames**: same as `@pytest.mark.parametrize` `argnames`.
- **fixture**: a fixture name string or a fixture symbol. If a fixture symbol is provided, the created fixtures will have the same scope. If a name is provided, they will have scope='function'. Note that in practice the performance loss resulting from using `function` rather than a higher scope is negligible since the created fixtures' body is a one-liner.
- **in_cls**: a boolean (default `False`). You may wish to turn this to `True` to use this function inside a class. If you do so, you **MUST** assign the output to variables in the class.
- **hook**: an optional hook to apply to each fixture function that is created during this call. The hook function will be called everytime a fixture is about to be created. It will receive a single argument (the function implementing the fixture) and should return the function to use. For example you can use `saved_fixture` from `pytest-harvest` as a hook in order to save all such created fixtures in the fixture store.
- **hook**: an optional hook to apply to each fixture function that is created during this call. The hook function will be called every time a fixture is about to be created. It will receive a single argument (the function implementing the fixture) and should return the function to use. For example you can use `saved_fixture` from `pytest-harvest` as a hook in order to save all such created fixtures in the fixture store.

**Outputs:** the created fixtures.

Expand Down Expand Up @@ -510,7 +510,7 @@ leads to very explicit ids: `<union>/<idx>/<alternative>`. See `UnionFixtureAlte
- `unpack_into`: an optional iterable of names, or string containing coma-separated names, for additional fixtures to create to represent parts of this fixture. See `unpack_fixture` for details.
- `ids`: as in pytest. The default value returns the correct fixture
- `autouse`: as in pytest
- `hook`: an optional hook to apply to each fixture function that is created during this call. The hook function will be called everytime a fixture is about to be created. It will receive a single argument (the function implementing the fixture) and should return the function to use. For example you can use `saved_fixture` from `pytest-harvest` as a hook in order to save all such created fixtures in the fixture store.
- `hook`: an optional hook to apply to each fixture function that is created during this call. The hook function will be called every time a fixture is about to be created. It will receive a single argument (the function implementing the fixture) and should return the function to use. For example you can use `saved_fixture` from `pytest-harvest` as a hook in order to save all such created fixtures in the fixture store.
- `kwargs`: other pytest fixture options. They might not be supported correctly.

**Outputs:** the new fixture. Note: you do not need to capture that output in a symbol, since the fixture is automatically registered in your module. However if you decide to do so make sure that you use the same name.
Expand Down Expand Up @@ -555,7 +555,7 @@ def test_uses_param2(arg1, arg2, fixture_uses_param2):
- `autouse`: see fixture `autouse`
- `ids`: same as `@pytest.mark.parametrize` `ids`
- `scope`: see fixture `scope`
- `hook`: an optional hook to apply to each fixture function that is created during this call. The hook function will be called everytime a fixture is about to be created. It will receive a single argument (the function implementing the fixture) and should return the function to use. For example you can use `saved_fixture` from `pytest-harvest` as a hook in order to save all such created fixtures in the fixture store.
- `hook`: an optional hook to apply to each fixture function that is created during this call. The hook function will be called every time a fixture is about to be created. It will receive a single argument (the function implementing the fixture) and should return the function to use. For example you can use `saved_fixture` from `pytest-harvest` as a hook in order to save all such created fixtures in the fixture store.
- `kwargs`: any other argument for the created 'fixtures'

### `param_fixture`
Expand Down Expand Up @@ -602,7 +602,7 @@ Both `fixture_ref` and `lazy_value` can be used to represent a single argvalue,

Finally, `pytest.param` is supported even when there are `fixture_ref` and `lazy_value`.

Here as for all functions above, an optional `hook` can be passed, to apply on each fixture function that is created during this call. The hook function will be called everytime a fixture is about to be created. It will receive a single argument (the function implementing the fixture) and should return the function to use. For example you can use `saved_fixture` from `pytest-harvest` as a hook in order to save all such created fixtures in the fixture store.
Here as for all functions above, an optional `hook` can be passed, to apply on each fixture function that is created during this call. The hook function will be called every time a fixture is about to be created. It will receive a single argument (the function implementing the fixture) and should return the function to use. For example you can use `saved_fixture` from `pytest-harvest` as a hook in order to save all such created fixtures in the fixture store.

**Parameters**

Expand All @@ -622,7 +622,7 @@ Here as for all functions above, an optional `hook` can be passed, to apply on e

- `scope`: The scope of the union fixture to create if `fixture_ref`s are found in the argvalues. Otherwise same as in `pytest.mark.parametrize`.

- `hook`: an optional hook to apply to each fixture function that is created during this call. The hook function will be called everytime a fixture is about to be created. It will receive a single argument (the function implementing the fixture) and should return the function to use. For example you can use `saved_fixture` from `pytest-harvest` as a hook in order to save all such created fixtures in the fixture store.
- `hook`: an optional hook to apply to each fixture function that is created during this call. The hook function will be called every time a fixture is about to be created. It will receive a single argument (the function implementing the fixture) and should return the function to use. For example you can use `saved_fixture` from `pytest-harvest` as a hook in order to save all such created fixtures in the fixture store.

- `debug`: print debug messages on stdout to analyze fixture creation (use pytest -s to see them)

Expand Down
4 changes: 2 additions & 2 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ Fixed [#48](https://github.com/smarie/python-pytest-cases/issues/48).

### 1.9.0 - New `--with-reorder` commandline option

New commandline option '--with-reorder' to change the reordering startegy currently in application. Fixes [#45](https://github.com/smarie/python-pytest-cases/issues/45).
New commandline option '--with-reorder' to change the reordering strategy currently in application. Fixes [#45](https://github.com/smarie/python-pytest-cases/issues/45).

The `--with-reorder` "skip" mode was not working correctly in presence of marks, fixed it. Fixed [#46](https://github.com/smarie/python-pytest-cases/issues/46).

Expand Down Expand Up @@ -562,7 +562,7 @@ Following [Sup3rGeo](https://github.com/Sup3rGeo)'s proposal, introduced two hel

### 1.4.2 - parametrized `@pytest_fixture_plus` minor bug fix

`@pytest_fixture_plus` now correctly honors parameter id and marks overriden at single parameter level using `pytest.param`. Fixed [#30](https://github.com/smarie/python-pytest-cases/issues/30).
`@pytest_fixture_plus` now correctly honors parameter id and marks overridden at single parameter level using `pytest.param`. Fixed [#30](https://github.com/smarie/python-pytest-cases/issues/30).

### 1.4.1 - parametrized `@pytest_fixture_plus` minor bug fix

Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ After starting to reuse cases in several test functions, you might end-up thinki

That being said, **if you are certain that your tests do not modify your cases data**, there are several ways to solve this issue:

- the easiest way is to **use fixtures with a broad scope**, as explained [above](#b-parametrizing-fixtures). However in some parametrization scenarii, `pytest` does not guarantee that the fixture will be setup only once for the whole session, even if it is a session-scoped fixture. Also the cases will be parsed everytime you run pytest, which might be cumbersome
- the easiest way is to **use fixtures with a broad scope**, as explained [above](#b-parametrizing-fixtures). However in some parametrization scenarii, `pytest` does not guarantee that the fixture will be setup only once for the whole session, even if it is a session-scoped fixture. Also the cases will be parsed every time you run pytest, which might be cumbersome

```python
from pytest_cases import parametrize, parametrize_with_cases, fixture
Expand Down
2 changes: 1 addition & 1 deletion docs/pytest_goodies.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ Another consequence of using [`fixture_ref`](./api_reference.md#fixture_ref) is

## passing a `hook`

As per version `1.14`, all the above functions now support passing a `hook` argument. This argument should be a callable. It will be called everytime a fixture is about to be created by `pytest_cases` on your behalf. The fixture function is passed as the argument of the hook, and the hook should return it as the result.
As per version `1.14`, all the above functions now support passing a `hook` argument. This argument should be a callable. It will be called every time a fixture is about to be created by `pytest_cases` on your behalf. The fixture function is passed as the argument of the hook, and the hook should return it as the result.

You can use this fixture to better understand which fixtures are created behind the scenes, and also to decorate the fixture functions before they are created. For example you can use `hook=saved_fixture` (from [`pytest-harvest`](https://smarie.github.io/python-pytest-harvest/)) in order to save the created fixtures in the fixture store.

Expand Down
6 changes: 3 additions & 3 deletions src/pytest_cases/case_parametrizer_new.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def parametrize_with_cases(argnames, # type: Union[str, List[str]
`test_<name>_cases.py` or if not found, `cases_<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.
or a list of such 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_parametrize_args`. This can be handy for debugging purposes.
Expand Down Expand Up @@ -469,7 +469,7 @@ def case_to_argvalues(host_class_or_module, # type: Union[Type, ModuleType]
if debug:
case_fun_str = qname(case_fun.func if isinstance(case_fun, functools.partial) else case_fun)
print("Case function %s > fixture_ref(%r) with marks %s" % (case_fun_str, fix_name, remaining_marks))
# return a lengh-1 tuple because there is a single case created
# return a length-1 tuple because there is a single case created
return (make_marked_parameter_value((argvalues,), marks=remaining_marks) if remaining_marks else argvalues,)


Expand Down Expand Up @@ -963,7 +963,7 @@ def get_current_params(request_or_item):
raise ValueError("Error: multiple values found for the same fixture parameter. Please report this issue")
fixture_results_dict[fixture_name] = fixture_results_dct

# the remainder: fixtures that cant be found.
# the remainder: fixtures that can't be found.
results_unknown_dict = dict()
for function, results_list in results_known_fixtures_but_not_found.items():
fixture_results_dct = dict(results_list)
Expand Down
2 changes: 1 addition & 1 deletion src/pytest_cases/common_pytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ def make_test_ids_from_param_values(param_names,
paramids = []
for _idx, vv in enumerate(param_values):
if len(vv) != nb_params:
raise ValueError("Inconsistent lenghts for parameter names and values: '%s' and '%s'"
raise ValueError("Inconsistent lengths for parameter names and values: '%s' and '%s'"
"" % (param_names, vv))
_id = mini_idvalset(param_names, vv, _idx)
paramids.append(_id)
Expand Down
10 changes: 5 additions & 5 deletions src/pytest_cases/fixture_core1_unions.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ def fixture_union(name, # type: str
fixtures to create to represent parts of this fixture. See `unpack_fixture` for details.
:param autouse: as in pytest
:param hook: an optional hook to apply to each fixture function that is created during this call. The hook function
will be called everytime a fixture is about to be created. It will receive a single argument (the function
will be called every time a fixture is about to be created. It will receive a single argument (the function
implementing the fixture) and should return the function to use. For example you can use `saved_fixture` from
`pytest-harvest` as a hook in order to save all such created fixtures in the fixture store.
:param kwargs: other pytest fixture options. They might not be supported correctly.
Expand Down Expand Up @@ -364,7 +364,7 @@ def _fixture_union(fixtures_dest,
:param unpack_into:
:param autouse:
:param hook: an optional hook to apply to each fixture function that is created during this call. The hook function
will be called everytime a fixture is about to be created. It will receive a single argument (the function
will be called every time a fixture is about to be created. It will receive a single argument (the function
implementing the fixture) and should return the function to use. For example you can use `saved_fixture` from
`pytest-harvest` as a hook in order to save all such created fixtures in the fixture store.
:param caller: a function to reference for error messages
Expand Down Expand Up @@ -468,7 +468,7 @@ def test_function(self, a, b):
:param in_cls: a boolean (default False). You may wish to turn this to `True` to use this function inside a class.
If you do so, you **MUST** assign the output to variables in the class.
:param hook: an optional hook to apply to each fixture function that is created during this call. The hook function
will be called everytime a fixture is about to be created. It will receive a single argument (the function
will be called every time a fixture is about to be created. It will receive a single argument (the function
implementing the fixture) and should return the function to use. For example you can use `saved_fixture` from
`pytest-harvest` as a hook in order to save all such created fixtures in the fixture store.
:return: the created fixtures.
Expand All @@ -490,12 +490,12 @@ def _unpack_fixture(fixtures_dest, # type: ModuleType
):
"""

:param fixtures_dest: if this is `None` the fixtures wont be registered anywhere (just returned)
:param fixtures_dest: if this is `None` the fixtures won't be registered anywhere (just returned)
:param argnames:
:param fixture:
:param in_cls: a boolean indicating if the `self` argument should be prepended.
:param hook: an optional hook to apply to each fixture function that is created during this call. The hook function
will be called everytime a fixture is about to be created. It will receive a single argument (the function
will be called every time a fixture is about to be created. It will receive a single argument (the function
implementing the fixture) and should return the function to use. For example you can use `saved_fixture` from
`pytest-harvest` as a hook in order to save all such created fixtures in the fixture store.
:return:
Expand Down
Loading