首页 > 解决方案 > 如何使用 pytest 运行 python 的跟踪?

问题描述

我正在尝试对使用 pytest 执行的程序运行跟踪。我正在尝试命令

python3 -m trace -t  pytest test_one.py 

但它给了我

Cannot run file 'pytest' because: [Errno 2] No such file or directory: 'pytest'

因为我假设 trace.py 需要一个文件。我看到了这个 类似的问题,但我有点难以理解应该是什么意思 - 它应该是 pytest 本身的可执行文件吗(我实际上没有看到它在我的计算机上,我找到了一个文件夹main.py 和 init.py 但我似乎看不到某些可执行文件),还是其他?

标签: pythonpytesttracebin

解决方案


如对引用问题的评论中所述,您必须用pytestpytest 可执行文件的实际路径替换:

python -m trace -c -m -C . <pytest_executable_absolute_path> test_script.py

在 *nix 下,您应该能够使用 本地化pytest可执行文件which pytest,在 Windows 下使用where pytest(感谢@hoefling 提醒我)。


推荐阅读