我正在使用 Selenium 在网站上运行测试。我需要运行许多单独的测试,并且想要创建一个脚本来运行某个文件夹中的所有 python 文件。我可以获取名称并导入模块,但是一旦这样做,我就无法让 unittest 运行文件。这是我创建的一些测试代码。我的问题似乎是,一旦我将名称作为字符串输入,我就无法摆脱它。
我想为每个文件夹编写其中一个文件,或者以某种方式执行目录中的所有文件夹。这是我到目前为止的代码:
\## This Module will execute all of the Admin>Vehicles>Add Vehicle (AVHC) Test Cases
import sys, glob, unittest
sys.path.append('/com/inthinc/python/tiwiPro/IE7/AVHC')
AddVehicle_IE7_tests = glob.glob('/com/inthinc/python/tiwipro/IE7/AVHC/*.py')
for i in range( len(AddVehicle_IE7_tests) ):
replaceme = AddVehicle_IE7_tests[i]
withoutpy = replaceme.replace( '.py', '')
withouttree1 = withoutpy.replace( '/com/inthinc/python/tiwipro/IE7/AVHC\\', '' )
exec("import " + withouttree1)
AddVehicle_IE7_tests[i] = withouttree1
sys.path.append('/com/inthinc/python/tiwiPro/FF3/AVHC')
AddVehicle_FF3_tests = glob.glob('/com/inthinc/python/tiwipro/FF3/AVHC/*.py')
for i in range( len(AddVehicle_FF3_tests) ):
replaceme = AddVehicle_FF3_tests[i]
withoutpy = replaceme.replace( '.py', '')
withouttree2 = withoutpy.replace( '/com/inthinc/python/tiwipro/FF3/AVHC\\', '' )
exec("import " + withouttree2)
print withouttree2
if __name__ == '__main__':
print AddVehicle_IE7_tests
unittest.TextTestRunner().run(AddVehicle_IE7_tests)
else:
unittest.TextTestRunner().run(AddVehicle_IE7_tests)
unittest.TextTestRunner().run(AddVehicle_FF3_tests)
print "success"