How can I see normal print output created during pytest run?

后端 未结 11 2011
轮回少年
轮回少年 2020-12-12 10:30

Sometimes I want to just insert some print statements in my code, and see what gets printed out when I exercise it. My usual way to \"exercise\" it is with existing pytest t

相关标签:
11条回答
  • 2020-12-12 10:43

    Try pytest -s -v test_login.py for more info in console.

    -v it's a short --verbose

    -s means 'disable all capturing'



    0 讨论(0)
  • 2020-12-12 10:44

    pytest --capture=tee-sys was recently added (v5.4.0). You can capture as well as see the output on stdout/err.

    0 讨论(0)
  • 2020-12-12 10:45

    You can also enable live-logging by setting the following in pytest.ini or tox.ini in your project root.

    [pytest]
    log_cli = True
    

    Or specify it directly on cli

    pytest -o log_cli=True
    
    0 讨论(0)
  • 2020-12-12 10:45

    The other answers don't work. The only way to see the captured output is using the following flag:

    pytest --show-capture all

    0 讨论(0)
  • 2020-12-12 10:47

    According to pytest documentation, version 3 of pytest can temporary disable capture in a test:

    def test_disabling_capturing(capsys):
        print('this output is captured')
        with capsys.disabled():
            print('output not captured, going directly to sys.stdout')
        print('this output is also captured')
    
    0 讨论(0)
  • 2020-12-12 10:49

    When running the test use the -s option. All print statements in exampletest.py would get printed on the console when test is run.

    py.test exampletest.py -s
    
    0 讨论(0)
提交回复
热议问题