Skip to content

Pytest parametrize unused argname inspection

This inspection reports parametrized argument names that are not used by the target test body or its fixture dependencies.

How to use it

Enable the inspection under Settings | BetterPy | Testing (Pytest) | Parametrize. BetterPy highlights unused argnames and the corresponding values.

Choose Capture unused parameters from an unused argname, value, or function parameter to keep the test cases and explicitly consume unused parameters:

@pytest.mark.parametrize("used, unused", [(1, 2), (3, 4)])
def test_example(used, unused):
    _ = unused
    assert used > 0

The fix captures unused direct parameters from the selected decorator in one assignment, after any docstring. For a class decorator, it updates collected test methods, including nested test classes. Fixture inputs and already-used parameters are left alone. Remove unused parametrize argname remains available when you want to remove the parameter and its values instead.

If _ already appears in the function, the capture uses a free name such as _unused or _unused1 instead, preserving existing parameter values and references.

Notes

  • The inspection accounts for stacked parametrize decorators.
  • Direct parametrization can override a fixture requested through another fixture, usefixtures, or an autouse fixture. The overridden name does not need to appear in the test signature.
  • Names routed through indirect=True or indirect=[...] remain fixture inputs. Dynamic indirect expressions are left unanalyzed.
  • It is gated by the Pytest parametrize unused argname setting.