首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >pytest特征分析主要报告pytest函数

pytest特征分析主要报告pytest函数
EN

Stack Overflow用户
提问于 2022-10-25 17:53:42
回答 1查看 76关注 0票数 1

为了分析我的代码,我安装了pytest-profiling并运行

代码语言:javascript
复制
$ pytest --profile

然而,摘要中的几乎所有结果都与pytest本身的功能有关:

代码语言:javascript
复制
   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
      159    0.001    0.000    0.170    0.001 runner.py:108(pytest_runtest_protocol)
      159    0.001    0.000    0.143    0.001 runner.py:116(runtestprotocol)
...
2615/1749    0.015    0.000    0.131    0.000 _callers.py:9(_multicall)
...

有没有办法让分析器忽略pytest的函数,而得到我的包的统计数据呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-11-05 04:47:57

目前,插件中似乎没有任何选项可以对显示的函数调用进行裁剪(源:插件回购)。

但是,您可以编写一个自定义脚本,只显示您感兴趣的分析结果(它保存在./prof/combined.prof上)。

代码语言:javascript
复制
import pstats

stats = pstats.Stats('./prof/combined.prof')
stats.print_stats("path/to/function_calls/you/want/to/show")

# Or alternatively
stats.print_stats("local_path", 20) # Only show 20 of the listings
stats.sort_stats('cumulative').print_stats('dir_name', 20) # Sort by cumulative time

然后您可以编写一个脚本(.sh.bat,.)它调用pytest --profile,后面跟着上面的代码片段。

有关pstats的更多信息:https://docs.python.org/3/library/profile.html

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74198259

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档