Skip to content

Doesn't appear to be a supported way for plugins to detect test failures at teardown #542

Closed
@pytestbot

Description

@pytestbot

Originally reported by: BitBucket: virtuald, GitHub: virtuald


What I'd like to be able to do is write a pytest plugin that would check proper usage of a fixture after a test has completed. If the test has failed, then I'd like to not do the check, since the additional error message would confuse the user.

I found a way to do it, but since I'm using an internal variable I suspect that it might be subject to breakage. Here's what I'm doing now:

#!python

def pytest_runtest_setup(item):
    item.__testsfailed = item.session._testsfailed

def pytest_runtest_teardown(item):
    if fixture_enabled and item.__testsfailed == item.session._testsfailed:
        # assert that the fixture was used properly

I'm open to other ways of implementing this, particularly if there's an officially supported way to do it. Thanks!


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