Skip to content

fix(pytest): ignore pytest internal fixture finalizers in teardown - #937

Merged
delatrie merged 1 commit into
allure-framework:masterfrom
nekdan:fix/pytest-9.1-internal-finalizer
Nov 20, 2026
Merged

delatrie merged 1 commit into
allure-framework:masterfrom
nekdan:fix/pytest-9.1-internal-finalizer

Conversation

@nekdan

@nekdan nekdan commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Fixes #918
Supersedes #921

Context

Starting from pytest 9.1.0, FixtureDef.execute() registers an internal lambda finalizer (lambda: request.node.ihook.pytest_fixture_post_finalizer(...)) into fixturedef._finalizers at index 0 before invoking pytest_fixture_setup.

Previously, AllureListener.pytest_fixture_setup wrapped all entries in fixturedef._finalizers with allure_commons.fixture. When pytest ran that internal finalizer at teardown, pytest_fixture_post_finalizer triggered allure_logger.stop_group() and flushed the TestResultContainer to disk before allure_commons.fixture reached stop_after_fixture(), leaving a phantom <fixture>::<lambda> entry with unknown status in every fixture teardown.

Changes

  • Record the number of pre-existing internal finalizers on fixturedef._finalizers before yield in AllureListener.pytest_fixture_setup and wrap only user-registered finalizers added during fixture execution.
  • Preserve user-defined request.addfinalizer(lambda: ...) reporting (unlike filtering by "<lambda>" name).
  • Add acceptance tests verifying both yield fixtures and explicit user lambda finalizers.

Checklist

@CLAassistant

CLAassistant commented Nov 12, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@delatrie delatrie left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nekdan Thank you for your contribution

@delatrie
delatrie merged commit c61a8f3 into allure-framework:master Nov 20, 2026
20 checks passed
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.

Phantom <lambda> teardown entries with unknown status when using pytest 9.1+

3 participants