美文网首页
(五)pytest-测试用例编写注意事项以及用例排序

(五)pytest-测试用例编写注意事项以及用例排序

作者: Sandra_liu | 来源:发表于2021-07-15 19:00 被阅读0次

1、pytest中class中不需要添加object
2、测试用例(module)以test开头或者以test结尾
类以Test开头
方法以test开头
3、用例排序:
方法一:
*模块级(setup_module/teardown_module):作用于模块(开始和结束各执行一次。)

*函数级(setup_function/teardown_function):仅对函数用例生效(不在类中,每个函数执行一次。)

*类级(setup_class/teardown_class):作用于类(在每个类中开始和结束各执行一次。)

*方法级(setup_method/teardown_method):作用于方法(在类中,每个方法开始和结束各执行一次。)

*类里面的(setup/teardown):作用于方法(每个方法执行一次。)

import logging
import os
import pytest

def setup_module():
    logging.info("setup_module")

def teardown_module():
    logging.info("teardown_module")

class Test_C:
    logging.info("class C")


class Test_D:
    @classmethod
    def setup_class(cls):
        logging.info("setup_class")

    @classmethod
    def teardown_class(cls):
        logging.info("teardown_class")

    def setup_method(self):
        logging.info("setup_method")

    def teardown_method(self):
        logging.info("teardown_method")

    def setup(self):
        logging.info("setup")

    def teardown(self):
        logging.info("teardown")

    # 列表断言
    def test_007(self):
        logging.info("7")
        # print(os.getcwd())
        assert [1, 2] == [3, 4]

    # 元组断言
    def test_008(self):
        logging.info("8")
        assert (1, 2) == (1, 2)

    # 字典断言
    def test_009(self):
        logging.info("9")
        assert {'a': 1, 'b': 2} == {'a': 1, 'b': 2}

if __name__ == '__main__':
    pytest.main(["-q", "--log-level=INFO" ,"-s","test_suite.py"])
image.png

方法二:pytest-ordering(已废弃)

#使用字母排序
import logging

import pytest


class Test_A2:
    logging.basicConfig(format='%(asctime)s - %(pathname)s[line:%(lineno)d] - %(levelname)s: %(message)s',
                        level=logging.INFO)
    @pytest.mark.first
    def test_001(self):
        logging.info("1")

    @pytest.mark.last
    def test_002(self):
        logging.info("2")

    @pytest.mark.second
    def test_003(self):
        logging.info("3")


    @pytest.mark.second_to_last
    def test_004(self):
        logging.info("4")


#使用数字排序
class Test_A1:
    @pytest.mark.run(order = 1)
    def test_001(self):
        logging.info("1")

    @pytest.mark.run(order =3)
    def test_002(self):
        logging.info("2")


    @pytest.mark.run(order = 2)
    def test_003(self):
        logging.info("3")


    @pytest.mark.run(order= 4)
    def test_004(self):
        logging.info("4")
if __name__ == '__main__':
    pytest.main(["-q", "--log-level=INFO" ,"-s","test_order_2.py"])


相关文章

  • (五)pytest-测试用例编写注意事项以及用例排序

    1、pytest中class中不需要添加object2、测试用例(module)以test开头或者以test结尾类...

  • 软件测试常见问题

    1、软件测试流程是什么? ①需求分析,需求评审②编写测试计划③编写测试用例,用例评审④执行测试,提交bug,回归测...

  • APP功能测试点总结(转载)

    1.功能性测试: ——根据产品需求文档编写测试用例。 ——软件设计文档编写用例。 注意:就是根据产品需求文档编写测...

  • APP测试点全面总结(上)

    1.功能性测试: ——根据产品需求文档编写测试用例。 ——软件设计文档编写用例。 注意:就是根据产品需求文档编写测...

  • APP测试点总结(全面)

    1.功能性测试: ——根据产品需求文档编写测试用例。 ——软件设计文档编写用例。 注意:就是根据产品需求文档编写测...

  • 测试用例的编写原则

    编写测试用例的最终目标是:一个对于产品毫无所知的人员,也能够快速的熟悉用例并执行用例 测试用例的编写原则: 1、 ...

  • 软件测试基本流程

    1.需求分析(产品经理) 2.编写测试用例(测什么,怎么测) 3.评审测试用例 4.搭建测试环境 5.等待开发提交...

  • APP测试点(功能、接口等)

    一、功能测试 ——根据产品需求文档编写测试用例。 ——软件设计文档编写用例。 注意:就是根据产品需求文档编写测试用...

  • 1.软件测试流程

    1.需求分析 2.编写测试用例(测什么,怎么测) 3.评审测试用例 4.搭建测试环境 5.等待开发提交测试包 6....

  • 测试用例编写

    测试用例要素 1.用例编号 从1开始,按顺序排列下去 2.测试项目 当前编写的用例的项目名,可以是测试用例所属...

网友评论

      本文标题:(五)pytest-测试用例编写注意事项以及用例排序

      本文链接:https://www.haomeiwen.com/subject/fbxupltx.html