【问题标题】:How do I run python's trace with pytest?如何使用 pytest 运行 python 的跟踪?
【发布时间】:2020-02-24 17:38:24
【问题描述】:

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

python3 -m trace -t  pytest test_one.py 

但它给了我

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

我假设 trace.py 需要一个文件。我看见了这个 similar question 但我有点难以理解应该是什么意思 - 它是否应该是 pytest 本身的可执行文件(我实际上没有看到它在我的计算机上的位置,我找到了一个主文件夹.py 和 init.py 但我似乎看不到某些可执行文件)或其他什么?

【问题讨论】:

  • 是的,这实际上是 pytest 可执行文件本身。在 *nix 下,您应该可以使用 which pytest 对其进行本地化,在 Windows 下,它位于 Scripts 下(在虚拟环境中或 Python 安装路径中,取决于您使用的内容)。
  • 我会将此视为引用问题的副本,但该问题没有被接受的答案(只有带有答案的评论)。
  • which pytest 在 Unix 上是 where pytest 在 Windows 上。 @MrBeanBremen 为什么不自己添加答案?这个问题已经有一年多了,OP不太可能很快给出答案。

标签: python pytest trace bin


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 2018-06-18
    • 2011-03-23
    • 1970-01-01
    • 2023-02-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多