zoukankan      html  css  js  c++  java
  • Pytest用例编写1

     
    一、编写pytest测试样例非常简单,只需要按照下面的规则:
    • 测试文件以test_开头(以_test结尾也可以)
    • 测试类以Test开头,并且不能带有 __init__ 方法
    • 测试函数以test_开头
    • 断言使用基本的assert即可
     
     
     
    二、执行测试样例的方法很多种,上面第一个实例是直接执行py.test,第二个实例是传递了测试文件给py.test。其实py.test有好多种方法执行测试
    py.test # run all tests below current dir
    py.test test_mod.py # run tests in module
    py.test somepath # run all tests below somepath
    py.test -k stringexpr # only run tests with names that match the
    # the "string expression", e.g. "MyClass and not method"
    # will select TestMyClass.test_something
    # but not TestMyClass.test_method_simple
    py.test test_mod.py::test_func # only run tests that match the "node ID",
    # e.g "test_mod.py::test_func" will select
    # only test_func in test_mod.py
     
    三、生成测试报告
    生成HTML格式报告:
    py.test --resultlog=path
    生成XML格式的报告:
    py.test --junitxml=path
  • 相关阅读:
    Android_程序未处理异常的捕获与处理
    instanceof关键字
    乐优商城项目爬坑
    [LeetCode]Isomorphic Strings
    [LeetCode]Contains Duplicate II
    [LeetCode]Valid Sudoku
    [LeetCode]Valid Anagram
    [LeetCode]Contains Duplicate
    [LeetCode]Single Number
    [LeetCode]Valid Number
  • 原文地址:https://www.cnblogs.com/TomBombadil/p/10977852.html
Copyright © 2011-2022 走看看