Skip to content

Provide callbacks or hooks that gets called before executing teardown class, teardown module #13799

@lakshminarayanareddybn

Description

@lakshminarayanareddybn

What's the problem this feature will solve?

"I have a test class that defines setup_class and teardown_class methods. I need to execute some specific configuration or cleanup code before the teardown_class method itself is invoked.

My current observation is that the teardown logic within a scope="class" fixture runs after the teardown_class method has already completed. How can I ensure my custom code (e.g., within a class scope fixture's teardown) reliably executes prior to the teardown_class method?"

Describe the solution you'd like

To implement "callbacks" or "hooks" that execute before teardown_class and teardown_module in pytest, the recommended and most effective solution is to utilize pytest fixtures with the yield keyword and appropriate scoping.

Alternative Solutions

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: needs informationreporter needs to provide more information; can be closed after 2 or more weeks of inactivity

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions