pytest_框架 - 用例查找规则

用例查找规则

阅读目录:
  用例查找规则
  演示

用例查找规则

pytest命令运行方式运行时,用例查找规则如下:

image
image

演示

数据 -- 总览
image
image
test_zcs_example.py
#!/usr/bin/env python
# _*_ coding: utf-8 _*_
# @Author: zzd
# @wx: M_Haynes
# @Blog: https://editor.mdnice.com/?outId=3922c88879f84d9d87275683f6153499
# 备注: 主要用于介绍pytest基本概念,以及运行方法 -- 第一课

import pytest
def inc(x):
    return x + 1

def test_a():
    print("---test_a")
    assert inc(0) == 1

class TestCase:
    def test_b(self):
        print("---test_b")
        assert "zz" in "zzd"

    def test_c(self):
        print("---test_c")
        assert 'c' in 'cao'

class TestCase2:
    def test_d(self):
        print("--test_d")
        assert 'dd' in 'caoindd'
test_example1.py

#!/usr/bin/env python

# _*_ coding: utf-8 _*_
# @Author: zzd
# @wx: M_Haynes
# @Blog: https://editor.mdnice.com/?outId=3922c88879f84d9d87275683f6153499
# 备注: 主要用于介绍pytest 用例查找规则 -- 第二课


import pytest

def test_e():
    print("--test_e--")
    assert 'in' in 'insert'
test_example2.py
#!/usr/bin/env python
# _*_ coding: utf-8 _*_
# @Author: zzd
# @wx: M_Haynes
# @Blog: https://editor.mdnice.com/?outId=3922c88879f84d9d87275683f6153499
# 备注: 主要用于介绍pytest 用例查找规则 -- 第二课

def test_example2():
    print("--- test_example2 ---")
    assert 'meiling' in 'caomeiling'

演示 -- 下面命令统一加上 -vs 参数

pytest --- 运行当前目录及子目录下所有用例 image pytest ./ -- 运行当前目录及子目录下所有用例 image pytest case\sub_case\ -- 运行执行目录及子目录下所有用例 image pyest -m pytest case\test_zcs_example.py -- 指定模块运行 image pytest -k test_2 -- 按关键字(函数/方法名)匹配运行 image python case/test_zcs_example.py::test_a -- 指定文件下的函数运行 image pytest test_zcs_example.py::Testcase -- 指定文件下的类运行 image pytest test_zcs_example.py::Testcase::test_c -- 指定类方法运行 image

本文由 mdnice 多平台发布

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

周承森

敲键盘不易~ 给点鼓励~ 感恩

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值