按书上学写测试pytest

Posted aguncn

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了按书上学写测试pytest相关的知识,希望对你有一定的参考价值。

慢慢的,这块知识也补好吧。

系统的学习框架,具体的细节,可以边百度边实现。

技术分享图片

test_three.py 

‘‘‘Test the Task data type.‘‘‘

from collections import namedtuple

Task = namedtuple(Task, [summary, owner, done, id])
Task.__new__.__defaults__=(None, None, False, None)

def test_defaults():
    t1 = Task()
    t2 = Task(None, None, False, None)
    assert t1 == t2

def test_member_access():
    t = Task(buy milk, brian)
    assert t.summary == buy milk
    assert t.owner == brian
    assert (t.done, t.id) == (False, None)
‘‘‘Test the Task data type‘‘‘

from collections import namedtuple

Task = namedtuple(Task, [summary, owner, done, id])
Task.__new__.__defaults__=(None, None, False, None)

def test_asdict():
    t_task = Task(do something, okken, True, 21)
    t_dict = t_task._asdict()
    expected = {summary: do something,
        owner: okken,
        done: True,
        id: 21}
    assert t_dict == expected

def test_replace():
    t_before = Task(finish book, brian, False)
    t_after = t_before._replace(id = 10, done = True)
    t_expected = Task(finish book, brian, True, 10)
    assert t_after == t_expected

技术分享图片

以上是关于按书上学写测试pytest的主要内容,如果未能解决你的问题,请参考以下文章

Appium+Pytest实现app并发测试

自动化脚本如何切换环境?Pytest这些功能你必须要掌握

盘点:细数Appium+Pytest是如何实现App并发测试的?

赶快收藏,Pytest框架环境切换实战教程

自动化脚本如何切换环境?Pytest这些功能你必须要掌握

一个使用Flask-Login登录后的Pytest测试用例的坑