Python-在模拟而不是列表中接收对象

时间:2018-10-02 13:14:46

标签: python python-unittest

每次执行时,我都会收到以下测试。似乎每次我收到对象而不是数据。

AssertionError: Expected call: print_posts(<post.Post object at 0x030EF030>)

测试代码:

 def test_print_posts(self):
        blog = app.blogs['Test']
        blog.create_post('Post title', 'Post content')

        with patch('app.print_posts') as mocked_print_post:
            app.print_posts(blog)

            mocked_print_post.assert_called_with(blog.posts[0])

测试方法的代码:

 def print_posts(blog):
     for post in blog.posts:
         print(post)

0 个答案:

没有答案