python - HTMLTestRunner报错:raise TypeError("{} is not callable".
天蓬老师
天蓬老师 2017-04-18 09:53:22
0
1
1669

Python3 在使用HTMLTestRunner时,报错:raise TypeError("{} is not callable".format(repr(test)))

代码如下:

import pymysql
import unittest
import time
import unittest.suite
import HTMLTestRunner
import sys
def hell(a):
    print(a)
    return a


testunit = unittest.TestSuite()
testunit.addTest(hell('ad'))

filename = '/Users/vivi/Downloads/aa.html'
fp = open(filename, 'wb')  # 之前写的是file(filename,'wb'),但是无法识别file方法,改成open,OK!
runner = HTMLTestRunner.HTMLTestRunner(stream=fp, title=u'print', description=u'简单')
runner.run(testunit)

运行后报错:

Traceback (most recent call last):
  File "/Applications/Python 3.5/……/B.py", line 30, in <module>
    testunit.addTest(hell('ad'))
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/unittest/suite.py", line 47, in addTest
    raise TypeError("{} is not callable".format(repr(test)))
TypeError: 'ad' is not callable
天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

모든 응답(1)
大家讲道理

unittest.TestSuite 인스턴스의 addTest() 메소드가 잘못 사용되었으며 매개변수가 잘못 전달되었습니다. unittest 모듈의 문서를 주의 깊게 읽는 것이 좋습니다.

코드 예를 들어보세요:

으아아아

최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!