2

I'm trying to use Pytest.

How do I set flags such that all tests run, logs only to be output on failure on a per test basis while the test is running, and silent otherwise?

I don't want it to hold my test failure logs hostage while waiting for the entire test suite to finish.

richliaw
  • 1,925
  • 16
  • 14

1 Answers1

-2

You should use pytest-sugar pytest package. It gives test failure information and python traceback as soon as any test fails.

Install using pip install pytest-sugar and run the tests normally.

More info here: https://github.com/Frozenball/pytest-sugar

Edit: If you don't want to see the passing test logs, you can pass -rf argument. More info here: https://stackoverflow.com/a/55367504/2312300

SilentGuy
  • 1,867
  • 17
  • 27
  • this didn't help or answer the question – cryanbhu Dec 22 '20 at 13:32
  • @cryanbhu How does it not answer the question? Have you tried the solution before passing the judgement? OP wanted to see the failure log as soon as test failure occurs instead of at the session finish. Pytest does not do that by default. Pytest-sugar plugin prints failure logs at the time of test failure instead of at session end time. – SilentGuy Dec 23 '20 at 17:58
  • now it answers the question after you edited it – cryanbhu Dec 28 '20 at 10:17
  • This was a two part question: > How do I set flags such that all tests run, logs only to be output on failure on a per test basis while the test is running, and silent otherwise? This part was not answered before edit. > I don't want it to hold my test failure logs hostage while waiting for the entire test suite to finish. This part was answered. But you said that the answer didn't help or answer the question at all without reading the question and answer fully. Please be considerate before dismissing answers and downvoting it. – SilentGuy Dec 28 '20 at 19:49