我有一個python中的main()函數,它獲取命令行參數。 有沒有辦法讓我爲這個函數編寫pytest測試並在代碼中定義參數?pytest:設置主函數測試的命令行參數
例如
def main():
# argparse code
args, other = arg_parser.parse_known_args()
return args.first_arg
def test_main():
res = main() # call with first_arg = "abc"
assert(res == "abc")