【发布时间】:2014-04-22 22:17:27
【问题描述】:
场景: 我的一个测试用例是执行一个带有几个输入文件和一个特定输出的 shell 程序。我想测试这些输入/输出的不同变体,每个变体都保存在自己的文件夹中,即文件夹结构
/testA
/testA/inputX
/testA/inputY
/testA/expected.out
/testB
/testB/inputX
/testB/inputY
/testB/expected.out
/testC/
...
这是我运行此测试的代码:
def test_folders(self):
tfolders = glob.iglob(os.environ['testdir'] + '/test_*')
for testpath in tfolders:
testname = os.path.basename(testpath)
self.assertTrue(self.runTest(testname))
在这种情况下,testname 是“testX”。它使用该文件夹中的inputs 执行外部程序,并将其与同一文件夹中的expected.out 进行比较。
问题: 一旦遇到失败的测试,测试就会停止并获得:
Could not find or read expected output file: C:/PROJECTS/active/CMDR-Test/data/test_freeTransactional/expected.out
======================================================================
FAIL: test_folders (cmdr-test.TestValidTypes)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\PROJECTS\active\CMDR-Test\cmdr-test.py", line 52, in test_folders
self.assertTrue(self.runTest(testname))
AssertionError: False is not true
问题: 我如何让它继续其余的测试并显示有多少失败? (本质上是动态创建一个单元测试并执行它)
谢谢
【问题讨论】:
-
看起来您需要制作一个测试套件,向其中添加测试并运行,请参阅此相关线程:stackoverflow.com/questions/3156782/…。
标签: python unit-testing testing assertions python-unittest