Show logging output for failed testcases last in pytest

Viewed 382

I am running pytest with the flags as such:
pytest test/test_app.py -rA -l

It shows logs for all cases, with the failed case logs first, meaning I have to scroll through a ton of logs to get to the top for the failed case logs.

Is there a way to only show failed case logs, or to show failed cases last, after the passed cases?

1 Answers

I have found a workflow that seems to work well for me. I am working on a Mac and using Terminal, so your hotkeys might be different.

  1. Before running the test I clear the existing terminal with Cmd+k
  2. Then I run my test, either with -rF or -rA depending on whether I want to see all logs or only failure cases
pytest test/test_app.py -rA -l
  1. after the run completes, I go to the top of the result (since it shows failures first) with the Home hotkey, which is Cmd+<up arrow>. This is quite useful in Mac terminal because it highlights the command in bright yellow after jumping to Home or End(Cmd+<down arrow>).
Related