AssertIn unittest with strings

时间:2017-09-14 08:36:46

标签: python python-unittest

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

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

该代码很容易测试:

 class Cooper():
    ...

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

在单元测试中:

Coop = Cooper()
...
p = os.path.join('/home/twinpeaks','CooperFBIdkaéfjkfjfdéjdakél')
print(Coop.FBI,type(Coop.FBI),type(p))
print (Coop.FBI in p)
self.assertIn(Coop.FBI,p)

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

但是我得到了输出:

 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

有什么问题?我有点卡住了......

0 个答案:

没有答案