
pytest
田晨|ggss
这个作者很懒,什么都没留下…
展开
-
unittest的断言
msg是发生异常时的错误提醒信息断言方法 断言描述 备注 assertEqual(arg1, arg2, msg=None) 验证arg1=arg2,不等则fail arg1 = arg2 assertNotEqual(arg1, arg2, msg=None) 验证arg1 != arg2, 相等则fail arg1 != arg2 assertTrue(ex原创 2020-06-03 14:32:14 · 131 阅读 · 0 评论 -
unittest使用
unittest核心工作原理unittest中最核心的四个概念是:test case, test suite, test runner, test fixture。下面我们分别来解释这四个概念的意思,先来看一张unittest的静态类图(下面的类图以及解释均来源于网络 一个TestCase的实例就是一个测试用例。什么是测试用例呢?就是一个完整的测试流程,包括测试前准备环境的搭建(...转载 2019-12-26 12:58:51 · 294 阅读 · 1 评论 -
testNG操作
https://blog.youkuaiyun.com/df0128/article/details/83243822转载 2020-05-25 17:31:34 · 108 阅读 · 0 评论 -
pytest的fixture固件
Pytest 使用 yield 关键词将固件分为两部分,yield 之前的代码属于预处理,会在测试前执行;yield 之后的代码属于后处理,将在测试完成后执行。@pytest.fixture()def db(): print('Connection successful') yield print('Connection closed')def search_user(user_id): d = { '001': 'xiaoming' }原创 2021-07-20 16:54:06 · 157 阅读 · 0 评论 -
pytest的mark使用
@pytest.mark标签使用1. @pytest.mark.skip(reason=’’)跳过运行@pytest.mark.skip(reason="run failed")def test_two(): a = "1" assert hasattr(a,"1")运行结果testCase2.py::test_two SKIPPED (run failed) 2. @pytest.mark.skipif(条件,reason=’’)跳过运行@pytest.mark.ski原创 2021-07-20 15:43:38 · 498 阅读 · 1 评论 -
pytest断言异常
import pytestdef test_raises(): with pytest.raises(TypeError) as e: a = 1 + "1" exec_msg = e.value.args[0] print("___",exec_msg) assert exec_msg == "unsupported operand type(s) for +: 'int' and 'str'"在测试过程中,经常需要测试是否如期抛出预期的异常,以确定异原创 2021-07-20 14:50:24 · 329 阅读 · 0 评论