Pit of print in pytest

background

When writing test cases using the pytest framework recently, in order to debug the case, I used print to print the relevant variable values, as shown below:

analysis

The setup_class and setup_method in the figure are called at the beginning of the class and before the use case is executed, but when actually running pytest xxx.py, the information printed by the print function is not output to the console!

At first, I suspected that the setup function was placed in the wrong place. I checked the official website document and found that the location was not wrong.

Where is the problem? Does pytest not output print statements by default? Then I went online to search around, only to find pytest does not print output to the console, if it is to print all of the content, the words "requires a runtime -s " parameter, which pytest -s xxx.py .

It turned out that the problem occurred when I didn't add the -s parameter. Because I started using the pytest framework directly and didn't read the documentation carefully, a very simple question made me confused for an hour.

Blogger: Test to make money

Motto: Focus on testing and automation, and strive to improve R&D efficiency; through testing and diligence to complete the original accumulation, through reading and financial management to financial freedom.

csdn:https://blog.csdn.net/ccgshigao

Blog Park: https://www.cnblogs.com/qa-freeroad/

51cto :https://blog.51cto.com/14900374


Guess you like

Origin blog.51cto.com/14900374/2596694