Skip to content

Warn on test arguments with default values? #12693

@The-Compiler

Description

@The-Compiler

As someone pointed out in my pytest training, pytest currently silently accepts:

def test_fixt(fixt=42):
    ...

with fixt obviously being 42 in the test function no matter if such a fixture was ever defined or not.

There doesn't really seem any valid reason to do this kind of thing, yet some ideas float around how default argument like this could be used in the future with either test functions (e.g. #3834) or with fixture functions (e.g. #8109).

To avoid accidental usage and possibly allow for different usage in the future, should we maybe add a warning if default argument values are used like this?

Activity

RonnyPfannschmidt

RonnyPfannschmidt commented on Aug 6, 2024

@RonnyPfannschmidt
Member

We should also propose this as a potential ruff rule

added
type: enhancementnew feature or API change, should be merged into features branch
on Oct 30, 2024
huangbenny

huangbenny commented on Dec 6, 2024

@huangbenny

I can take this as my first issue

The-Compiler

The-Compiler commented on Jan 19, 2025

@The-Compiler
MemberAuthor

For what it's worth, flake8-pytest-style seems to have added a rule for this: https://github.com/m-burst/flake8-pytest-style/blob/master/docs/rules/PT028.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: enhancementnew feature or API change, should be merged into features branch

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Warn on test arguments with default values? · Issue #12693 · pytest-dev/pytest