问题的代码是你是不是有新的创造套件名称替换的args列表的套件。
检查了这一点
args = ['test_file']
print "Before args are -",args
for suite in args:
#Checks test word
if suite.startswith('test'):
#If yes, append "hello.tests"
new_suite="hello.tests."+suite
#Replace it in args list
args[args.index(suite)]=new_suite
print "After args are -",args
输出:
C:\Users\dinesh_pundkar\Desktop>python c.py
Before args are - ['test_file']
After args are - ['hello.tests.test_file']
C:\Users\dinesh_pundkar\Desktop>
以上可以使用列表理解也执行。
args = ['test_file',"file_test"]
print "Before args are -",args
args = ["hello.tests."+suite if suite.startswith('test') else suite for suite in args]
print "After args are -",args
它应该工作,另外,请参见[MCVE] – Lafexlos
您可以发布您的代码? – Don
为什么startswith不起作用?你能解释 – armak