pytest学习实践-day10:执行指定的nodeid 的测试用例

新增文件名:test_06_nodeid.py ,代码如下:

import pytest


def test_one():
    print("test_one")
    assert 1 == 2


class TestNode(object):
    def test_one(self):
        print("TestNode::test_one")
        assert 1

    # 这里是参数化
    # 循环执行2次,第一遍取 x=1,y=1;第2次 x=3,y=4
    @pytest.mark.parametrize('x,y', [(1, 1), (3, 4)])
    def test_two(self, x, y):
        print(f'TestNode::test_two::{x} == {y}')
        assert x == y


# 1.在文件目录下,指定 函数名 test_one 执行
# pytest -q -s.\test_06_nodeid.py::test_one

# 2.在文件目录下,指定 类名+函数名 test_one 执行
# pytest -q -s.\test_06_nodeid.py::TestNode::test_one

# 3.在文件目录下,指定 类名+函数名 test_two 执行
# pytest -q -s.\test_06_nodeid.py::TestNode::test_two

# 3.1这里可以使用 --collect-only 查看用例名称,注意,这2个参数没有空格
#  pytest -q -s --collect-only .\test_06_nodeid.py::TestNode::test_two
# 输出:
# test_06_nodeid.py::TestNode::test_two[1-1]
# test_06_nodeid.py::TestNode::test_two[3-4]

# 3.2 使用 -k 过滤对应用例
# PS E:\learnPython\01_01_pytest_book> pytest -q -s -k 'one and not Test' .\test_06_nodeid.py
#
# 4 deselected in 0.01s
# PS E:\learnPython\01_01_pytest_book> pytest -q -s -k 'one and not TestNode' .\test_06_nodeid.py
# test_one
# F
# ====================================================== FAILURES =======================================================
# ______________________________________________________ test_one _______________________________________________________
#
#     def test_one():
#         print("test_one")
# >       assert 1 == 2
# E       assert 1 == 2
#
# test_06_nodeid.py:6: AssertionError
# =============================================== short test summary info ===============================================
# FAILED test_06_nodeid.py::test_one - assert 1 == 2
# 1 failed, 3 deselected in 0.24s
  • 4
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值