Pytest framework runs common parameter parsing

 
 
  1. -s: Indicates to output debugging information, which is used to display the information printed by print() in the test function. Let's add a sentence of print(driver.title) to the use case, let's run our use case again to see the debug information output
  2. -v: Only print the module name before adding v, after adding v --verbose prints the class name, module name, method name, and displays more detailed information.
  3. -vs: These two parameters can be used together
  4. -n: Support multi-threaded or distributed running test cases (need to install: pytest-xdist plugin)
    #命令行运行:
    pytest -vs test_login.py -n 2
    # 多线程执行测试用例,第1,3,5用例给线程0,第2,4用例给线程1
    # ----不管用例执行时间多长,比如设置1的等待时长为5秒,也是1,3分给线程0
    
    #主函数运行:
    pytest.main(['-vs','test_login.py', '-n=2'])
    
    #运行指定模块
    pytest.main(['-vs','test_0617.py'])
    
  5. –reruns NUM: Rerun failure cases, run several times (need to install: pytest-rerunfailures plugin)
    #命令行运行:
    pytest -vs ./testcase/test_login.py reruns 2
    
    #主函数运行:
    pytest.main(['-vs','./testcase/test_login.py','--reruns=2'])
    
  6. -x: Indicates that as long as one test case reports an error, the execution stops
  7. –maxfail=2: Indicates that 2 use case errors are reported, and the execution stops. 
    #命令行运行
    pytest -vs ./testcase --maxfail 2
    
    #主函数运行
    pytest.main(['-vs', './testcase', '--maxfail=2'])
    
  8. -k: Fuzzy matching, part of the string of the test case, specifies the execution of the test case. 
    #命令行运行:
    pytest -vs ./testcase -k "ao"
    
    #主函数运行:
    pytest.main(['-vs', './testcase', '-k=ao'])
    
  9. -q: Indicates that only the overall test results are displayed. --quiet : Minimalist result display, simplifying the output of the console, it can be seen that the output information is different from that without adding -q information before, and the two .. dots in the running result replace the pass result
  10. –html ./report/report.html: Generate a test report in html format (need to install: pytest-html plugin)
  11. -m: --mark mark
  12. order: Change the default execution order of use cases
  13. skip: skip the use case
    #Unconditionally skip 
    @pytest.mark.skip(reason="pan4 is too beautiful") #Conditionally skip 
    @pytest.mark.skipif(age>=18, reason='grown up')
  14. smoke: Smoke use cases are distributed in various modules, how to execute them in groups? Smoke use cases, sub-modules, sub-interfaces and web implementations. Can be used together with not, or, and to meet different conditions to filter
    #Execute test_login.py This file is not a use case marked with smoke 
    pytest -vs -m "not smoke" test_login.py 
    #Execute test_login.py This file is a use case marked with smoke and usermanage 
    pytest -vs -m "smoke or usermanage" test_login.py   
    #Execute the use cases marked with smoke and usermanage and productmange under all files 
    pytest -vs -m "smoke or usermanage or productmange" 
    #Add the corresponding field in the pytest.ini configuration file : addopts = -vs, the command line can not be used use -vs
     pytest -m "smoke or usermanage or productmanage"

 

Pytest framework test case rules and operation methods Reference: Pytest framework test case rules and operation methods_Momo18S Blog-CSDN Blog

Guess you like

Origin blog.csdn.net/weixin_37600187/article/details/128332400