我可以在运行时传递命令行参数
python <filename>.py arg1
Run Code Online (Sandbox Code Playgroud)
但是当我尝试传递运行 pytest 的命令行参数时,它失败并给出如下错误。你能给些建议么。
pytest <filename>.py arg1
ERROR: file not found: arg1
Run Code Online (Sandbox Code Playgroud)
编辑:
例如,我正在考虑以这种方式使用它,假设我已经传递了一个参数并且正在通过 sys.argv 读取它:
import sys
arg = sys.argv[3]
def f():
return 3
def test_function():
assert f() == arg
Run Code Online (Sandbox Code Playgroud) python ×1