Skip to content

pytest_pyfunc_call hookwrapper not called with tests that subclass unittest.TestCase #3550

Closed
@lita

Description

@lita

I am in the middle of writing a pytest plugin and noticed that pytest_pyfunc_call is not called on tests that have unittest.TestCase subclassed. This method is called correctly when the test class subclasses object or just plain function tests.

I have created a simple example to explain the bug.

conftest.py

@pytest.hookimpl(hookwrapper=True)
def pytest_pyfunc_call(pyfuncitem):
    outcome = yield

    try:
        outcome.get_result()  # will raise if outcome was exception
        print('success')
    except Exception:
        print('Failed')
import unittest


class TestStupid(unittest.TestCase):
    def test_a(self):
        assert 1 == 1


    def test_b(self):
        assert 2 == 2


    def test_error(self):
        assert 2 != 2

I am using pytest==3.6.1 on Python 3.6. Tried it on a Mac and Ubuntu Trusty.

I can get around the issue by using pytest_runtest_setup and pytest_runtest_teardown but unable to get the result of the test this way.

Metadata

Metadata

Assignees

No one assigned

    Labels

    plugin: unittestrelated to the unittest integration builtin plugintype: questiongeneral question, might be closed after 2 weeks of inactivity

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions