pytest学习实践-day9- 执行指定目录下,或者 指定匹配 方法名的用例

"""1.指定当前目录 具体模块  pytest .\test_01_first.py"""

"""1.指定执行某个目录 pytest 目录/"""

# pytest -k "test_1 or TestCase"
// 参数k :主要搜索 当前目录的 函数名 或 类名   ,可以使用 and  or 做逻辑筛选

# pytest -v 文件名 -k "test_1 or TestCase"
// 参数k :主要搜索 当前目录的 函数名 或 类名   ,可以使用 and  or 做逻辑筛选

# pytest - v.\01_01_pytest_book\ -k "test_1"

------------------

test_06_-m参数执行指定标记的用例.py , 文件,代码如下:

import pytest
"""-m 全称 market,可以通过方法名称的表达式灵活筛选测试某种方法,和不测试相关方法"""
""" 
    pytest -v XXX.py 
    pytest -v -m 'p0' XXX.py
    pytest -v -m 'not p0' XXX.py
    pytest -v -m 'not p0 and not func' XXX.py
    pytest -v -m 'func or postgres' XXX.py
"""


@pytest.mark.ps
def test_sth_01():

    print("test_sth_01")


@pytest.mark.func
def test_sth_02():
    print("test_sth_02")


@pytest.mark.postgres
def test_sth_03():
    print("test_sth_03")


"""1. 执行 pytest -v .\test_06_-m参数执行指定标记的用例.py  (警告信息可以忽略)"""
# PS E:\learnPython\01_01_pytest_book> pytest -v .\test_06_-m参数执行指定标记的用例.py
# ================================================= test session starts =====================================
# platform win32 -- Python 3.11.3, pytest-7.4.2, pluggy-1.3.0 -- E:\python\python.exe
# cachedir: .pytest_cache
# rootdir: E:\learnPython\01_01_pytest_book
# collected 3 items
#
# test_06_-m参数执行指定标记的用例.py::test_sth_01 PASSED                                                          [ 33%]
# test_06_-m参数执行指定标记的用例.py::test_sth_02 PASSED                                                          [ 66%]
# test_06_-m参数执行指定标记的用例.py::test_sth_03 PASSED                                                          [100%]


"""2.执行 包含ps标记的用例
    pytest -v -m 'ps' .\test_06_-m参数执行指定标记的用例.py
"""
# PS E:\learnPython\01_01_pytest_book> pytest -v -m 'p1' .\test_06_-m参数执行指定标记的用例.py
# ================================================= test session starts ==============================================
# platform win32 -- Python 3.11.3, pytest-7.4.2, pluggy-1.3.0 -- E:\python\python.exe
# cachedir: .pytest_cache
# rootdir: E:\learnPython\01_01_pytest_book
# collected 3 items / 2 deselected / 1 selected
#
# test_06_-m参数执行指定标记的用例.py::test_sth_p1 PASSED                                                          [100%]
# ================================================== warnings summary ================================================
# 新增配置文件:pytest.ini文件注册标记,可以去除标记警告,具体配置语法如下:
# [pytest]
#
# markers =
#     main
#     标记2

# # 用例前面加载标签:@pytest.mark.标签名
# @pytest.mark.main
#  def test_demo():
#     pass


"""3.执行执行不包含 ps标记的用例 
    pytest -v -m 'not ps' .\test_06_-m参数执行指定标记的用例.py   
"""
# PS E:\learnPython\01_01_pytest_book> pytest -v -m "not ps" .\test_06_-m参数执行指定标记的用例.py
# ================================================= test session starts =============================================
# platform win32 -- Python 3.11.3, pytest-7.4.2, pluggy-1.3.0 -- E:\python\python.exe
# cachedir: .pytest_cache
# rootdir: E:\learnPython\01_01_pytest_book
# collected 3 items / 1 deselected / 2 selected
#
# test_06_-m参数执行指定标记的用例.py::test_sth_02 PASSED                                                          [ 50%]
# test_06_-m参数执行指定标记的用例.py::test_sth_03 PASSED                                                          [100%]
#
# ================================================== warnings summary ===============================================
# test_06_-m参数执行指定标记的用例.py:12
#   E:\learnPython\01_01_pytest_book\test_06_-m参数执行指定标记的用例.py:12: PytestUnknownMarkWarning:
# Unknown pytest.mark.ps - is this a typo?
# You can register custom marks to avoid this warning - for details,
#     see https://docs.pytest.org/en/stable/how-to/mark.html
#     @pytest.mark.ps
#
# test_06_-m参数执行指定标记的用例.py:18
#   E:\learnPython\01_01_pytest_book\test_06_-m参数执行指定标记的用例.py:18: PytestUnknownMarkWarning: Unknown pytest.
# mark.func - is this a typo?  You can register custom marks to avoid this warning - for details, see
#     https://docs.pytest.org/en/stable/how-to/mark.html
#     @pytest.mark.func
#
# test_06_-m参数执行指定标记的用例.py:23
#   E:\learnPython\01_01_pytest_book\test_06_-m参数执行指定标记的用例.py:23: PytestUnknownMarkWarning:
# Unknown pytest.mark.postgres - is this a typo?  You can register custom marks to avoid this warning -
# for details, see https://docs.pytest.org/en/stable/how-to/mark.html
#     @pytest.mark.postgres
#
# -- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
# ===================================== 2 passed, 1 deselected, 3 warnings in 0.05s ================================
  • 20
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值