2017-08-24 60 views
0

我習慣用命令狀從代碼運行測試與ARG

pytest.main('-s path_to_file --my_fixtures_arg1 arg_value') 

目前,這樣的電話被認爲是過時運行測試,你需要通過參數列表來調用這個命令。但我無法以任何方式傳遞必要的參數。誰知道解決方案?

回答

1
目前我使用的,因爲經過串已被廢棄的參數列表

如果字符串來自DB,配置文件或那樣的你可以這樣做。在你的情況,我認爲這應該工作:

arguments = ['-s', '--my_fixtures_arg1=arg_value', 'path_to_file'] 
pytest.main(args=arguments) 
0

當前pytestusesshlex.split將字符串拆分爲參數列表。

import shlex, sys 
args_list = shlex.split(args_string, posix=sys.platform != "win32")