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...

6
  • 1
    docs.pytest.org/en/latest/capture.html - I have used the -s option before and it worked for me. Try it out. Commented Mar 28, 2019 at 14:29
  • Otherwise: stackoverflow.com/questions/46201912/… Commented Mar 28, 2019 at 14:35
  • Possible duplicate of Python pytest: capturing stdout always fails Commented Mar 28, 2019 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? Commented Mar 28, 2019 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) Commented Mar 28, 2019 at 16:52

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.