New issue 542: Doesn't appear to be a supported way for plugins to detect test failures at teardown https://bitbucket.org/hpk42/pytest/issue/542/doesnt-appear-to-be-a-supported-way-for
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! _______________________________________________ pytest-commit mailing list pytest-commit@python.org https://mail.python.org/mailman/listinfo/pytest-commit