問題的代碼是你是不是有新的創造套件名稱替換的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