coincidence.params

pytest.mark.parametrize decorators.

Functions:

count(stop[, start, step])

Returns a pytest.mark.parametrize decorator which provides a list of numbers between start and stop with an interval of step.

whitespace_perms([ratio])

Returns a pytest.mark.parametrize decorator which provides permutations of whitespace.

testing_boolean_values([extra_truthy, …])

Returns a pytest.mark.parametrize decorator which provides a list of strings, integers and booleans, and the boolean representations of them.

param(*values[, marks, id, idx, key])

Specify a parameter in pytest.mark.parametrize calls or parametrized fixtures.

parametrized_versions(*versions[, reasons])

Return a list of parametrized version numbers.

count(stop, start=0, step=1)[source]

Returns a pytest.mark.parametrize decorator which provides a list of numbers between start and stop with an interval of step.

The single parametrized argument is count.

Parameters
  • stop (int) – The stop value passed to range.

  • start (int) – The start value passed to range. Default 0.

  • step (int) – The step passed to range. Default 1.

Return type

MarkDecorator

whitespace_perms(ratio=0.5)[source]

Returns a pytest.mark.parametrize decorator which provides permutations of whitespace.

For this function whitespace is only ␣\n\t\r.

Not all permutations are returned, as there are a lot of them; instead a random selection of the permutations is returned. By default ½ of the permutations are returned, but this can be configured using the ratio argument.

The single parametrized argument is char.

Parameters

ratio (float) – The ratio of the number of permutations to select to the total number of permutations. Default 0.5.

Return type

MarkDecorator

testing_boolean_values(extra_truthy=(), extra_falsy=(), ratio=1)[source]

Returns a pytest.mark.parametrize decorator which provides a list of strings, integers and booleans, and the boolean representations of them.

The parametrized arguments are boolean_string for the input value, and expected_boolean for the expected output.

Optionally, a random selection of the values can be returned using the ratio argument.

Parameters
  • extra_truthy (Sequence) – Additional values to treat as True. Default ().

  • extra_falsy (Sequence) – Additional values to treat as False. Default ().

  • ratio (float) – The ratio of the number of values to select to the total number of values. Default 1.

Return type

MarkDecorator

param(*values, marks=(), id=None, idx=None, key=None)[source]

Specify a parameter in pytest.mark.parametrize calls or parametrized fixtures.

Examples:

@pytest.mark.parametrize("test_input, expected", [
    ("3+5", 8),
    param("6*9", 42, marks=pytest.mark.xfail),
    param("2**2", 4, idx=0),
    param("3**2", 9, id="3^2"),
    param("sqrt(9)", 3, key=itemgetter(0)),
])
def test_eval(test_input, expected):
    assert eval (test_input) == expected

New in version 0.4.0.

Parameters
  • *values (~_T) – Variable args of the values of the parameter set, in order.

  • marks (Union[MarkDecorator, Collection[Union[MarkDecorator, Mark]]]) – A single mark or a list of marks to be applied to this parameter set. Default ().

  • id (Optional[str]) – The id to attribute to this parameter set. Default None.

  • idx (Optional[int]) – The index of the value in *values to use as the id. Default None.

  • key (Optional[Callable[[Tuple[~_T, …]], str]]) – A callable which is given values (as a tuple) and returns the value to use as the id. Default None.

Return type

ParameterSet

Overloads
parametrized_versions(*versions, reasons=())[source]

Return a list of parametrized version numbers.

Examples:

@pytest.mark.parametrize(
    "version",
    parametrized_versions(
        3.6,
        3.7,
        3.8,
        reason="Output differs on each version.",
        ),
    )
def test_something(version: str):
    pass
@pytest.fixture(
    params=parametrized_versions(
        3.6,
        3.7,
        3.8,
        reason="Output differs on each version.",
        ),
    )
def version(request):
    return request.param

def test_something(version: str):
    pass

New in version 0.4.0.

Parameters
  • *versions (Union[str, float, Tuple[int, …]]) – The Python versions to parametrize.

  • reasons (Union[str, Iterable[Optional[str]]]) – The reasons to use when skipping versions. Either a string value to use for all versions, or a list of values which correspond to *versions. Default ().

Return type

List[ParameterSet]