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

Logs before rerun appear in html report

Open orgads opened this issue 2 years ago • 8 comments

import logging

logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
seq_num = 0

def seq():
  global seq_num
  seq_num += 1
  return seq_num

def test_fail():
  logger.info(f'Test log {seq()}')
  assert False

pytest --reruns 1 --html=report.html

The report has logs of both runs:

def test_fail():
      logger.info(f'Test log {seq()}')
>     assert False
E     assert False

test_my.py:17: AssertionError

------------------------------ Captured log call -------------------------------
INFO     test_my:test_my.py:16 Test log 1


------------------------------ Captured log call -------------------------------
INFO     test_my:test_my.py:16 Test log 2

It looks like there is logic in _process_logs to skip rerun logs, but this function is not called (maybe it was changed in pytest).

    # Don't add captured output to reruns
    if report.outcome != "rerun":

orgads avatar Dec 22 '23 13:12 orgads

What's the expectation here? 🤔

Shouldn't the final result have all logs? Including those of reruns?

Maybe it looks like it doesn't on a trivial example, but in the real world the logs might contain crucial information to solve flaky logic.

BeyondEvil avatar Jan 07 '24 19:01 BeyondEvil

From my point of view, only the logs of the last (re)run matter.

orgads avatar Jan 07 '24 19:01 orgads

Ok, maybe that makes sense if the logs for previous runs are available in those runs in the report.

Can you clarify what you mean when you say that "_process_logs" isn't called?

@orgads

BeyondEvil avatar Jan 07 '24 19:01 BeyondEvil

I didn't say it isn't called, maybe it's called earlier, or maybe not in the right context, or maybe I misunderstood its purpose :)

orgads avatar Jan 07 '24 19:01 orgads

heh, ok.

I'll explore the behaviour in 3.x and compare.

BeyondEvil avatar Jan 07 '24 19:01 BeyondEvil

From my point of view, only the logs of the last (re)run matter.

I would think the exact opposite, myself. Why don't you care seeing logs from previous failures that force a rerun? Those test cases are the most flaky, and therefore of the most interest.

jeffwright13 avatar Jan 08 '24 15:01 jeffwright13

Right, but if it failed 3 times, and each run produces many logs, having the logs duplicated is cumbersome. I assume that if all runs failed, then the last run shouldn't be much different than the previous ones.

orgads avatar Jan 08 '24 15:01 orgads

We're running a plugin called pytest-rerunfailures. We might expect to see output from reruns :-)

jeffwright13 avatar Jan 08 '24 19:01 jeffwright13