码迷,mamicode.com
首页 > 其他好文 > 详细

按书上学写测试pytest

时间:2018-07-24 23:39:38      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:sdi   测试   src   png   test   data   info   collect   lse   

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

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

技术分享图片

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

标签:sdi   测试   src   png   test   data   info   collect   lse   

原文地址:https://www.cnblogs.com/aguncn/p/9363123.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!