python - 如何使用 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 但我似乎看不到某些可执行文件),还是其他?
解决方案
如对引用问题的评论中所述,您必须用pytest
pytest 可执行文件的实际路径替换:
python -m trace -c -m -C . <pytest_executable_absolute_path> test_script.py
在 *nix 下,您应该能够使用 本地化pytest
可执行文件which pytest
,在 Windows 下使用where pytest
(感谢@hoefling 提醒我)。
推荐阅读
- linux - perl 和 bash 变量替换,使用十六进制字符和重复计数
- javascript - 当您使用 npm 安装一个库和另一个将以前的库作为依赖项的库时会发生什么
- google-chrome - IDX21323 OpenIdConnectProtocolValidationContext.Nonce 为空
- postgresql - 无法从本地系统连接到 AWS RDS Postgres
- python-3.x - 如何从循环中的列表中选择一个随机单词?
- python - python(anaconda) 来自 php 的 exec()
- excel - 如何在Excel VBA中将单击的按钮BackColor格式化为黄色?
- python - Pathlib 使用“$”“规范化”UNC 路径
- perl - 如何使用 Perl 查找字符串中元音的数量
- javascript - 如何检查 NodeJS 中是否未定义某个属性