如何使用 pytest 运行 python 的跟踪? [英] How do I run python's trace with pytest?

查看:61
本文介绍了如何使用 pytest 运行 python 的跟踪?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to run a trace on a program that is executed with pytest. I am trying the command

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 的文件夹,但我似乎看不到一些可执行文件),或者还有什么?

as I am assuming trace.py is expecting a file. I saw this similar question but I'm a bit struggling to understand what is supposed to mean - is it supposed to be the executable file for pytest itself (I actually don't see where that is on my computer, I found a folder to a main.py and init.py but I can't seem to see some executable), or something else?

推荐答案

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

As stated in a comment to the referenced question, you have to substitute pytest by the actual path to the pytest executable:

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

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

Under *nix, you should be able to localize the pytest executable using which pytest, under Windows using where pytest (thanks to @hoefling for reminding me of that).

这篇关于如何使用 pytest 运行 python 的跟踪?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆