gpt4 book ai didi

python - 单元测试测试套件

转载 作者:太空宇宙 更新时间:2023-11-03 20:39:22 25 4
gpt4 key购买 nike

我有一个测试套件,并且执行了相同的操作,但是我的测试套件执行了单个测试脚本两次。我只想执行一次测试脚本,并且应该生成相同的报告。

Import HTMLTestRunner

class SmokeTestSuite(unittest.TestCase):
print('Running test suite')

dir = os.getcwd()
testLoad = unittest.TestLoader()
print(dir)
test_classes_to_run = [xyz_test_class]

suites_list = []
for test_class in test_classes_to_run:
suite = testLoad.loadTestsFromTestCase(test_class)
suites_list.append(suite)
print(suites_list)
newSuite = unittest.TestSuite(suites_list)
print(newSuite.countTestCases())
timestr = time.strftime("_%Y-%m-%d_%H.%M.%S")

resultFile = open(os.path.join(dir, "TestReport"+ timestr + ".html"), "w")
runner = HTMLTestRunner(stream=resultFile, title='Test Report', description='Tests Execution Report')

runner.run(newSuite)

它执行了单个测试脚本 xyz_test_class 两次。

最佳答案

TestCase 是一个类,子级应该定义测试方法,例如 test_foo(self)。因此,将代码放入方法中,如下所示:

class SmokeTestSuite(TestCase):
def test_smoke(self):
'''your code goes here'''

无论如何,你为什么不直接使用自动发现功能呢?

关于python - 单元测试测试套件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56952871/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com