tôi đã cố gắng:Làm thế nào để tôi tạo một thử nghiệm Suite trong python unittest
def buildTestSuite():
suite = unittest.TestSuite()
for testcase in glob.glob('src/testsuite/test_*.py'):
module = os.path.splitext(testcase)[0]
print module
print type(module)
suite.addTest(__import__(module).buildTestSuite())
return suite
nhưng tôi nhận được eror:
Traceback (most recent call last):
File "runtests.py", line 63, in ?
results = main()
File "runtests.py", line 57, in main
results = unittest.TextTestRunner().run(buildTestSuite())
File "runtests.py", line 53, in buildTestSuite
suite.addTest(__import__(module).buildTestSuite())
AttributeError: 'module' object has no attribute 'buildTestSuite'
lỗi: Traceback (cuộc gọi gần đây nhất): File "runtes ts.py ", dòng 64, trong? results = main() Tệp "runtests.py", dòng 58, trong chính results = unittest.TextTestRunner(). Run (buildTestSuite()) Tệp "runtests.py", dòng 52, trong buildTestSuite module = __import __ (modname, fromlist = '1') LoạiError: __import __() không có đối số từ khóa – kamal
'__import__' chấp nhận đối số từ khóa trong Python2.6 + (ít nhất). Bạn đang sử dụng phiên bản Python nào? – unutbu
Tôi đang sử dụng Python 2.4.3 – kamal