Skip to content

pytest_configure: injecting variables into pytest namespace is mypy-incompatible with pytest 8 #11880

@sigma67

Description

@sigma67

Hello, thanks for your great and invaluable work on pytest. I just updated to pytest 8 and I'm getting linter errors on the following scenario:

https://docs.pytest.org/en/latest/deprecations.html#pytest-namespace

import pytest


def pytest_configure():
    pytest.my_symbol = MySymbol()

The error:

error: Module has no attribute "my_symbol" [attr-defined]

As this approach is mentioned in the docs I'd expect it to still work.

  • Is there a way to still do this without disabling mypy everywhere the variable is used?
  • Is there a different approach that is considered better?

Context: I'm using the variable to share data between a pytest plugin I develop and the module (i.e. module defines the variable - plugin uses it).

pytest 8.0.0, mypy 1.8.0

  • a detailed description of the bug or problem you are having
  • output of pip list from the virtual environment you are using
  • pytest and operating system versions
  • minimal example if possible

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: questiongeneral question, might be closed after 2 weeks of inactivity

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions