pytest-assume icon indicating copy to clipboard operation
pytest-assume copied to clipboard

pytest-assume prevents captured log/stdout to appear `call` reports

Open Sup3rGeo opened this issue 3 years ago • 3 comments

Hi,

I think this is a consequence of https://github.com/astraw38/pytest-assume/pull/42. I remember back in time, I picked pytest-assume instead of pytest-check because of its use of pytest_pyfunc_call, as it would seamlessly integrate with other (reporting) plugins like Allure.

However, with this change to use pytest_runtest_call instead, now we cannot get the captured logs of the call section anymore in the report yielded at pytest_runtest_makereport.

The dummy test run is:

@pytest.fixture
def dummy_fix():
    logging.info("Setup!")
    yield
    logging.info("Teardown!")


@pytest.mark.dummy
def test_dummy_fail_assume(dummy_fix):
    logging.info("Got here sucessfully")
    with assume: assert 1 == 2

This is what I am checking, the report variable:

@pytest.hookimpl(hookwrapper=true)
    def pytest_runtest_makereport(self, item, call):
        report = (yield).get_result()

With pytest_runtest_call I get:

image

With pytest_pyfunc_call I get (manually changing the hook in plugin.py):

image

We can see that in the first case we don't have the logs for the call section.

Sup3rGeo avatar Jun 23 '21 11:06 Sup3rGeo

One possible solution is to implement both hook calls pytest_runtest_call and pytest_pyfunc_call which defer to a meta function containing all the logic (after the yield).

pytest_pyfunc_call would always call the meta function and register it in a per-item flag, which pytest_runtest_call could check to decide whether to run the meta function itself in case pyfunc_call was not called.

Sup3rGeo avatar Jun 24 '21 07:06 Sup3rGeo

I think that'd be an acceptable fix. The bug would likely still exist for unittest-based projects, but I was never very happy with the change required to make unittest-projects work.

I'll still dig around to see if there's a way to get the captured log without the double hook though.

astraw38 avatar Jun 24 '21 12:06 astraw38

I am preparing a PR, will open soon so you can take a look EDIT: ok now I see you said without the double hook :)

Sup3rGeo avatar Jun 24 '21 12:06 Sup3rGeo