运行我的脚本时出现以下错误:[error] NameError(全局名称' FNC_POS_GCH_TestSuite'未定义)

时间:2015-08-26 13:21:31

标签: python nameerror

我需要创建一个由套件组成的测试套件。我编写了以下代码来创建套件并获取名称错误global name is not defined

# IMPORTS, SETTINGS AND VARIABLES - do not edit
commonPath = "C:\\SikuliX\\AutomatedTest\\COMMON"
scriptPath1 = "C:\\SikuliX\\AutomatedTest\\TESTSCRIPTS\\GCH_GENERAL_CREDIT_HANDLING\\FNC_POS_GCH_GENERAL_CREDIT_HANDLING"
scriptPath2 ="C:\\SikuliX\\AutomatedTest\\TESTSCRIPTS\\DM_DEMO_MODE\\FNC_POS_DM_DEMO_MODE"
scriptPath3 ="C:\\SikuliX\\AutomatedTest\\TESTSCRIPTS\\SS_SESSION_START\\FNC_POS_SS_SESSION_START"
from sikuli import *
import sys
if not commonPath in sys.path: sys.path.append(commonPath)
if not scriptPath1 in sys.path: sys.path.append(scriptPath1)
if not scriptPath2 in sys.path: sys.path.append(scriptPath2)
if not scriptPath3 in sys.path: sys.path.append(scriptPath3)
import os
import datetime
import unittest
import HTMLTestRunner
from FNC_POS_GCH_TestSuite import *
from FNC_POS_DM_Start_DemoMode_TestSuite import *
from FNC_POS_SS_TestSuite import *

def suite():
    #masterSuite = unittest.TestSuite()
    #masterSuite.addTests(FNC_POS_GCH_TestSuite.suite())
    #masterSuite.addTests(FNC_POS_DM_Start_DemoMode_TestSuite.suite())
    #masterSuite.addTests(FNC_POS_SS_TestSuite.suite())
    s1 = FNC_POS_GCH_TestSuite.suite()
    s2 = FNC_POS_DM_Start_DemoMode_TestSuite.suite()
    masterSuite = unittest.TestSuite([s1, s2])
    return masterSuite

def main():
    today = datetime.datetime.now().strftime("%Y%m%d-%H%M%S")
    startDate = str(today)
    dir = "C:/Reports/"
    fileList = os.listdir(dir)
    [ os.remove(os.path.abspath(os.path.join(dir,fileName))) for fileName in fileList ]
    filename = startDate+"_TESTSUITE_MasterSuite_Report.html"
    print filename
    fp = file(os.path.join(dir, filename), "wb")
    runner = HTMLTestRunner.HTMLTestRunner(stream = fp, verbosity=2)
    result = runner.run(suite())
    fp.close()
    count = str(result.success_count+result.failure_count+result.error_count),
    Pass = str(result.success_count),
    fail = str(result.failure_count),
    error = str(result.error_count),
    text_file = open(dir+"/Summary.txt", "a")
    text_file.write("Summary of the Scripts: "+filename + "\n")
    text_file.write("Total Scripts executed : %s" % count + "\n")
    text_file.write("Scripts  Passed        : %s" % Pass + "\n")
    text_file.write("Scripts  Failed        : %s" % fail + "\n" )
    text_file.write("Scripts  Error         : %s" % error + "\n" )
    text_file.close()

if __name__ == '__main__':    
    main() 

如果您能告诉我脚本出错的地方,我将不胜感激。

0 个答案:

没有答案