如何在 python 单元测试中检查断言空字符串?

How to check assert empty string in python unittest?

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

我试过:

self.assertIsNone(msg)

但是我得到一个错误

AssertionError: '' is not None

所以我继续

self.assertIsEmpty(msg)

但是我得到了

object has no attribute 'assertIsEmpty'

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

您正在寻找

assertEqual(x, '')

Documentation for Python 3

Documentation for Python 2.7