AssertIn unittest with strings 字符串断言单元测试

2024-06-11 06:34:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在写一些unittest,想用AssertIn进行字符串比较。在

我有一个实例对象Cooper,属性为FBI,返回str类型

代码很简单要测试的类:

 class Cooper():
    ...

    @property
    def FBI(self):
        return self._FBI

在单元测试中:

^{pr2}$

在阅读了Function assertIn causes the UnicodeDecodeError之后,我检查了代码的第一行是#——编码:utf-8--

但我得到的输出是:

 twinpeaks/CopperFBI /home/twinpeaks/CooperFBIdkaéfjkfjfdéjdakél'  <class 'str'> <class 'str'>
 True
 E.s
 ======================================================================
 ERROR: test_class_Path (Code.tests.UtilsTests.UtilsTest)
 ----------------------------------------------------------------------
 Traceback (most recent call last):
 File "/home/twinpeaks/PythonCode/Code/tests/UtilsTests.py", line 68, in    test_Cooper
 self.assertIn(Cooper.FBI,p)
 File "/home/twinpeaks/anaconda3/envs/ana3/lib/python3.6/unittest/case.py", line 1085, in assertIn
 if member not in container:
 TypeError: 'in <string>' requires string as left operand, not NoneType

有什么问题吗?我有点卡住了,那里。。。在


Tags: 代码intestselfhomecodetestsunittest