Logging within pytest tests

后端 未结 2 1511
南方客
南方客 2020-12-04 07:25

I would like to put some logging statements within test function to examine some state variables.

I have the following code snippet:

import pytest,os
i         


        
2条回答
  •  庸人自扰
    2020-12-04 08:08

    Works for me, here's the output I get: [snip -> example was incorrect]

    Edit: It seems that you have to pass the -s option to py.test so it won't capture stdout. Here (py.test not installed), it was enough to use python pytest.py -s pyt.py.

    For your code, all you need is to pass -s in args to main:

     pytest.main(args=['-s', os.path.abspath(__file__)])
    

    See the py.test documentation on capturing output.

提交回复
热议问题