用例查找规则
阅读目录:
用例查找规则
演示
用例查找规则
pytest命令运行方式运行时,用例查找规则如下:

演示
数据 -- 总览

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 --- 运行当前目录及子目录下所有用例 pytest ./ -- 运行当前目录及子目录下所有用例
pytest case\sub_case\ -- 运行执行目录及子目录下所有用例
pyest -m pytest case\test_zcs_example.py -- 指定模块运行
pytest -k test_2 -- 按关键字(函数/方法名)匹配运行
python case/test_zcs_example.py::test_a -- 指定文件下的函数运行
pytest test_zcs_example.py::Testcase -- 指定文件下的类运行
pytest test_zcs_example.py::Testcase::test_c -- 指定类方法运行
本文由 mdnice 多平台发布