Python. 报错: TypeError: issubclass() arg 1 must be a class

时间:2021-07-02 17:02:21

Python. 报错: TypeError: issubclass() arg 1 must be a class

Traceback (most recent call last):
File "E:/2017work/2017年12月/Pytest/UnittestTest/TestTest.py", line 5, in <module>
suite1=unittest.TestLoader().loadTestsFromTestCase(UnittestTest.MyTest)
File "D:\Python36\lib\unittest\loader.py", line 86, in loadTestsFromTestCase
if issubclass(testCaseClass, suite.TestSuite):
TypeError: issubclass() arg 1 must be a class

解决办法:

造成该问题的原因是unitestTest.MyTest只是定位到了 MyTest这个文件,并没有定位到MyTest的这个类,正确的到类应该为: 

UnittestTest.MyTest.MyTest