This rule raises an issue when a pytest test or fixture parameter declares a default value.

Why is this an issue?

A default on a pytest test or fixture parameter is always used. Pytest does not inject a fixture of the same name when a default is present:

@pytest.fixture
def value():
    return 42

def test_positive(value=1):  # Always gets 1; fixture is ignored
    assert value > 0

That hides missing fixtures and makes the test run with a hard-coded value instead of the intended fixture. Remove the default so pytest can inject the parameter, or stop treating the name as a fixture dependency.

What is the potential impact?

Defaults on test or fixture parameters silently block fixture injection, so tests can pass with hard-coded values while the real fixture is never applied.

How to fix it

Remove default values from pytest test and fixture parameters so fixtures can be injected by name.

Code examples

Noncompliant code example

import pytest

@pytest.fixture
def value():
    return 42

def test_with_default(value=1):  # Noncompliant
    assert value > 0

Compliant solution

import pytest

@pytest.fixture
def value():
    return 42

def test_with_default(value):
    assert value > 0

Resources

Documentation

Related rules