pytest-assume
pytest-assume copied to clipboard
pytest-assume prevents captured log/stdout to appear `call` reports
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:
With pytest_pyfunc_call
I get (manually changing the hook in plugin.py
):
We can see that in the first case we don't have the logs for the call
section.
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.
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.
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 :)