Getting started with pytest testing (ExitCode)

Preface

When using the pytest framework, it often involves secondary packaging of pytest commands, such as writing a shell or python script to call pytest. The advantage of this is that it can provide users with several running scenarios and simplify the use of pytest command line parameters. The packaging script needs to judge the exit code of the actual running pytest command, and then make a logical judgment and return it to the actual user for viewing.

So let me share the exit code of the pytest framework.

analysis

As shown in the figure below, it is the enumeration class of exit code of pytest: ExitCode.

Execute python3, enter: from pytest import ExitCode

Then enter: help(ExitCode)

As can be seen from the above, there are six exit codes for pytest:

0  : All test cases run successfully

1  : Part (or all) of the test case operation results failed

2 : The test execution process is interrupted by the user (that is, the user performs the Ctrl + C command during the test case)

3 : An internal error has occurred (may be some runtime errors of the python script)

4 : pytest command line usage error (may not pass the correct command line parameters)

5 : The case is not actually executed (maybe an empty test class is executed)

View exit code

After running pytest xxx, after the script is executed, you can enter on the command line: echo $?  to view the exit code.

Extended exit code

If you want to extend the above exit codes and define more abundant scenarios, you can use the pytest-custom_exit_code plugin to achieve.


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/2595112