astral-sh / ruff

An extremely fast Python linter and code formatter, written in Rust.
https://docs.astral.sh/ruff
MIT License
30.91k stars 1.02k forks source link

Catch `hypothesis.errors.InvalidArgument` due to multiple `@given` decorators #13038

Open petermattia opened 3 weeks ago

petermattia commented 3 weeks ago

List of keywords you searched for before creating this issue. Write them down here so that others can find this issue more easily and help provide feedback.

It would be cool if ruff could automatically detect this hypothesis issue. Much faster to detect statically than during testing.

Catch FAILED src/tests/test_logic.py::test_check_value_is_greater_than_zero - hypothesis.errors.InvalidArgument: You have applied @given to the test test_check_value_is_greater_than_zero more than once, which wraps the test several times and is extremely slow. A similar effect can be gained by combining the arguments of the two calls to given. For example, instead of @given(booleans()) @given(integers()), you could write @given(booleans(), integers())
dhruvmanila commented 2 weeks ago

I'm not familiar with hypothesis but I wonder if a codemod is available for this using https://hypothesis.readthedocs.io/en/latest/extras.html#hypothesis-codemods.

dhruvmanila commented 2 weeks ago

Note: https://github.com/astral-sh/ruff/issues/7272#issuecomment-1714819109