4

I am trying to debug a feature of a test (that runs on pytest) I am setting a debug point and stop there (using Pycharm) However, I cannot debug efficiently the code because my stdout and stderr are redirected since this is a pytest. I tried restoring stdout from sys.__stdout__ but sys.stdout = sys.__stdout__ did not work.

Is there any way to restore stdout in order to debug?

This is not a duplicate of python-pytest-capturing-stdout-always-fails, capturing std is not failing in my case, it's captured at a location that is not really helping me to debug...

ntg
  • 12,950
  • 7
  • 74
  • 95
  • 1
    https://docs.pytest.org/en/latest/capture.html - I have used the -s option before and it worked for me. Try it out. – DemetriOS Mar 28 '19 at 14:29
  • Otherwise: https://stackoverflow.com/questions/46201912/python-pytest-capturing-stdout-always-fails – DemetriOS Mar 28 '19 at 14:35
  • Possible duplicate of [Python pytest: capturing stdout always fails](https://stackoverflow.com/questions/46201912/python-pytest-capturing-stdout-always-fails) – DemetriOS Mar 28 '19 at 14:35
  • Could you share a piece of your code with sys.stdout redirection? Do you use virtualenv in PyCharm or debugging in local environment? – andnik Mar 28 '19 at 14:38
  • 1
    @DemetriOS: -s worked :) If someone answers it, I ll accept that answer :) I don't think its a duplicate since Its not that the output is not printed, as in the link, its that it does not go to the output and I cannot see it to debug... Also -s is not proposed as a solution (since i think it can't solve that question) – ntg Mar 28 '19 at 16:52
  • @ntg answered it. Glad i could help. – DemetriOS Mar 28 '19 at 17:18

1 Answers1

3

Utilize the -s option while running pytest. As shown here: https://docs.pytest.org/en/latest/capture.html.
The -s option disables all capturing of stdout.

DemetriOS
  • 181
  • 13