首页 > 解决方案 > 如何在python unittest中检查断言空字符串?

问题描述

我有一个问题,我想msg = ''在 python unittest 中测试给定的空字符串,但我找不到正确的断言函数。

我尝试过:

self.assertIsNone(msg)

但我有一个错误

AssertionError: '' is not None

所以我继续

self.assertIsEmpty(msg)

但我得到了

object has no attribute 'assertIsEmpty'

因此,在 unittest 中检查空字符串的正确方法是什么?谢谢

标签: python-2.7python-unittest

解决方案


你正在寻找

assertEqual(x, '')

Python 3 的文档

Python 2.7 的文档


推荐阅读