Detailed explanation of Pytest parameters - based on command line mode

1、--collect-only

See which test cases will be executed under a given configuration

2、-k

Use expressions to specify the test cases you want to run. If the test name is unique or multiple test names have the same prefix or suffix, you can use expressions to quickly locate them, for example:

Command line -k parameter.png

3、-m

Markers are used to mark tests and group them for quick selection and running. Use @pytest.mark to mark.

  • You can use -m "mark1 and mark2" to select all test cases with these two marks at the same time.
  • Using -m "mark1 and not mark2" will select test cases with mark1 and filter out test cases with mark2.
  • Use -m "mark1 or mark2" to select all test cases with mark1 or mark2

4、-x

Normally pytest will run each collected test case. If a test case assertion fails, or an exception is triggered, then the execution of the test case will stop here. pytest will mark it as failed and move on to the next test case. But when debugging, if you need to stop the entire session immediately when you encounter a failure, you can add -x. After debugging, -x can be removed, and -tb=no can be used to turn off error message backtracking.

5、--maxfail=num

-x is to stop running when it encounters a failure, and --maxfail can specify how many times it is allowed to fail, and stop running after reaching the maximum number of failures

6、-s 与 --capture=method

-s Equivalent to --capture=no, turns off output capture. Normally, any conforming output stream information is captured. When --capture=fd, if the file descriptor (file descriptor) is 1 or 2, it will be output to a temporary file. sys.stdout/stderr will be output to memory when --capture=sys is used.

7、-l/--showlocals

Prints local variable names and their values ​​when tests fail to avoid unnecessary print statements

8、--if/--ff

When one or more test cases fail, if you want to locate the last failed test case and rerun, you can use --lf. --ff is basically the same as --lf, the difference is that --ff will run the rest of the test cases

9、-v

Make the output information more detailed. If it is not added, each file will display one line. After adding it, each test case will display one line. The test name and result will be displayed instead of just a point or a character

10、-q

Contrary to -v, simplify the output information.

11、--tb=style

  • --tb=style: Determines the display style of output information when capturing failures.
  • --tb=no: block all traceback information
  • --tb=line: print the position of the error
  • --tb=short: more verbose than no and line, give error message
  • --tb=long: output the most detailed information
  • --tb=auto: default value, if multiple test cases fail, only print the traceback information of the first and last test case, the format is long
  • --tb=native: Only output the backtrace information of the Python standard library

12、--duration=N

It can speed up the test rhythm and count which stage in the test process is the slowest, including call, setup, and teardown of test cases. It will display the slowest N stages, and the longer the time-consuming, the higher the front. If N = 0, it will display all stages in order of time-consuming from long to short

The following are supporting learning materials. For friends who do [software testing], it should be the most comprehensive and complete preparation warehouse. This warehouse also accompanied me through the most difficult journey. I hope it can help you too!

Software testing interview applet

The software test question bank maxed out by millions of people! ! ! Who is who knows! ! ! The most comprehensive quiz mini program on the whole network, you can use your mobile phone to do the quizzes, on the subway or on the bus, roll it up!

The following interview question sections are covered:

1. Basic theory of software testing, 2. web, app, interface function testing, 3. network, 4. database, 5. linux

6. web, app, interface automation, 7. performance testing, 8. programming basics, 9. hr interview questions, 10. open test questions, 11. security testing, 12. computer basics

Information acquisition method:

Guess you like

Origin blog.csdn.net/jiangjunsss/article/details/132083367