8000 Pytest 9.2 deprecated fixture defined as instance method by zartavr · Pull Request #303 · everypinio/hardpy · GitHub
[go: up one dir, main page]

Skip to content

Pytest 9.2 deprecated fixture defined as instance method - #303

Open
zartavr wants to merge 4 commits into
developfrom
fix/pytest_deprecate_fixture_as_instance_method
Open

zartavr wants to merge 4 commits into
developfrom
fix/pytest_deprecate_fixture_as_instance_method

Conversation

@zartavr
@zartavr zartavr commented Nov 30, 2026
Copy link
Copy Markdown

About

Fixtures defined as instance methods with session scope are deprecated since pytest 9.2.0. Pytest docs

The warning is emitted when post_run_functions or hardpy_start_args is used:

minimal_example/test_1.py::test_one
  .../.venv/lib/python3.14/site-packages/_pytest/fixtures.py:1392: PytestRemovedIn10Warning: Session-scoped fixtures defined as instance methods are deprecated.
  Instance attributes set in the 'post_run_functions' fixture will NOT be visible to test methods,
  as each test gets a new instance while the fixture runs only once per class.
  Use a @classmethod decorator below @pytest.fixture and set attributes on cls instead.
  See https://docs.pytest.org/en/stable/deprecations.html#class-scoped-fixture-as-instance-method
    fixturefunc = resolve_fixture_function(fixturedef, request)

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html

Reproduce

  • Copy minimal_example dir
  • Add conftest.py with the content below
  • Start hardpy

conftest.py

import pytest

def finish_executing():
    print("Testing completed")

@pytest.fixture(scope="session", autouse=True)
def fill_actions_after_test(post_run_functions: list):
    post_run_functions.append(finish_executing)
    yield

Suggested fix

  • Decorate HardpyPlugin fixtures as @classmethod
  • Store data in pytest Config.stash

pytest.Config instance is created once per session (pytest run). It has
pytest.Stash type member which is mutable key-value storage.

Public API is unchanged.

@zartavr
zartavr changed the base branch from main to develop December 1, 2026 16:29
@zartavr zartavr self-assigned this Dec 1, 2026

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0