pytest学习实践-day1-测试函数格式

import pytest


def test_1():
    assert 1 == 2, '不相等'
    print("这是1个测试方法")


def test_3():
    print("这是2个测试方法")


def t_3():
    print("这是3个测试方法")


# 默认只执行 test_开头的函数,同一个模块,优先执行test_开头函数,再执行测试类
if __name__ == 'main':
    """1、CMD模式:在当前目录,输入pytest 即可"""
    # pytest[option][file_or_dir][file_or_dir]...    # 中括号是可选项
    # pytest[参数操作][文件或文件夹]

    # pytest.main(["-x", "test_01_first.py"]) 执行到错误会停止
    # pytest.main(["-s", "test_01_first.py"]) 执行全部

    """2.通过python终端: python -m pytest """

    """3. 代码种执行:pytest.main('-q',__file__)  ,其中 -q 是quite缩写,表示静默执行,__file__是当前文件名"""
    pytest.main(["-s", "test_01_first.py"])
    pytest.main('-q', __file__)

    # 控制台 pytest -s 输出控制台信息
    # pytest -q 静默执行,不显示详细信息
    # pytest -x 执行失败终止
    # pytest -q -rA 静默执行,不显示详细信息,结束后打印 全部的简短的报告
    # pytest -q -rf 静默执行,不显示详细信息,结束后打印 失败的断言
    # pytest -q -rE 静默执行,不显示详细信息,结束后打印 出错的断言
    # pytest -q -rs 静默执行,不显示详细信息,结束后打印 跳过执行的

    # pytest -q -rp 静默执行,不显示详细信息,结束后打印 成功执行的

    # pytest -q -rP 静默执行,不显示详细信息,结束后打印 成功执行的,并输出print
    # pytest -q -ra 静默执行,不显示详细信息,结束后打印 非成功的
    # pytest -q -rfs  静默执行,不显示详细信息,结束后打印 失败的断言

总结:

1.测试执行成功,默认通过,且可以用断言判断 assert

2.pytest 一般收集以 test_ 开头 的测试函数这类用例,其他不会被统计到执行;

3.手动在 pycharm种按模块执行时,可以添加 以下 方便执行(直接选择文件也可以执行)

pytest.main(["-s", "当前模块名"])
pytest.main('-q', __file__)
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值