Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 单元测试套件_Python_Unit Testing - Fatal编程技术网

Python 单元测试套件

Python 单元测试套件,python,unit-testing,Python,Unit Testing,我有一个测试套件,我执行了相同的测试,但我的测试套件只执行了一个测试脚本两次。我只想执行测试脚本一次,并且应该为相同的脚本生成报告 Import HTMLTestRunner class SmokeTestSuite(unittest.TestCase): print('Running test suite') dir = os.getcwd() testLoad = unittest.TestLoader() print(dir) test_clas

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

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_类。

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

class SmokeTestSuite(测试用例):
def测试_烟雾(自身):
''你的代码在这里''

无论如何,为什么不使用自动发现呢?

TestCase是一个类,孩子们应该定义测试方法,比如
test\u foo(self)
。所以,将代码放入方法中,如下所示:

class SmokeTestSuite(测试用例):
def测试_烟雾(自身):
''你的代码在这里''

反正,为什么不使用自动发现工具?

我是python自动化新手,所以我只是探索和尝试python工具,为什么没有太多关于所有功能的信息。问题没有解决,上面的代码仍然面临同样的问题。我是python自动化新手,所以我只是探索和尝试python工具,为什么没有太多关于所有功能的信息功能。问题没有解决,上面的代码仍然面临相同的问题。