跳转到主要内容

pytest的配置插件

项目描述

pytest的配置插件,具有表格和热图输出。

使用cProfile对测试进行配置,并使用pstats进行分析;热图使用gprof2dotdot生成。

安装

使用您喜欢的包安装程序进行安装

pip install pytest-profiling
# or
easy_install pytest-profiling

在您的测试或conftest.py中明确启用fixture(使用setuptools入口点时不需要)

pytest_plugins = ['pytest_profiling']

使用方法

安装后,插件为pytest提供额外选项

$ py.test --help
...
  Profiling:
    --profile           generate profiling information
    --profile-svg       generate profiling graph (using gprof2dot and dot
                        -Tsvg)

--profileprofile-svg 选项可以与任何其他选项结合使用

$ py.test tests/unit/test_logging.py --profile
============================= test session starts ==============================
platform linux2 -- Python 2.6.2 -- pytest-2.2.3
collected 3 items

tests/unit/test_logging.py ...
Profiling (from prof/combined.prof):
Fri Oct 26 11:05:00 2012    prof/combined.prof

         289 function calls (278 primitive calls) in 0.001 CPU seconds

   Ordered by: cumulative time
   List reduced from 61 to 20 due to restriction <20>

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        3    0.000    0.000    0.001    0.000 <string>:1(<module>)
      6/3    0.000    0.000    0.001    0.000 core.py:344(execute)
        3    0.000    0.000    0.001    0.000 python.py:63(pytest_pyfunc_call)
        1    0.000    0.000    0.001    0.001 test_logging.py:34(test_flushing)
        1    0.000    0.000    0.000    0.000 _startup.py:23(_flush)
        2    0.000    0.000    0.000    0.000 mock.py:979(__call__)
        2    0.000    0.000    0.000    0.000 mock.py:986(_mock_call)
        4    0.000    0.000    0.000    0.000 mock.py:923(_get_child_mock)
        6    0.000    0.000    0.000    0.000 mock.py:512(__new__)
        2    0.000    0.000    0.000    0.000 mock.py:601(__get_return_value)
        4    0.000    0.000    0.000    0.000 mock.py:695(__getattr__)
        6    0.000    0.000    0.000    0.000 mock.py:961(__init__)
    22/14    0.000    0.000    0.000    0.000 mock.py:794(__setattr__)
        6    0.000    0.000    0.000    0.000 core.py:356(getkwargs)
        6    0.000    0.000    0.000    0.000 mock.py:521(__init__)
        3    0.000    0.000    0.000    0.000 skipping.py:122(pytest_pyfunc_call)
        6    0.000    0.000    0.000    0.000 core.py:366(varnames)
        3    0.000    0.000    0.000    0.000 skipping.py:125(check_xfail_no_run)
        2    0.000    0.000    0.000    0.000 mock.py:866(assert_called_once_with)
        6    0.000    0.000    0.000    0.000 mock.py:645(__set_side_effect)


=========================== 3 passed in 0.13 seconds ===========================

每个测试项目都会保留一个 pstats 文件(保存在 prof 目录中),以及一个 combined.prof 文件,用于后续分析。

$ ls -1 prof/
combined.prof
test_app.prof
test_flushing.prof
test_import.prof

默认情况下,pstats 文件以对应的测试名称命名,非法文件系统字符将被下划线替换。如果完整路径超过了操作系统允许的长度,则将其重命名为测试名称MD5散列的前4个字节。

$ ls -1 prof/
combined.prof
test_not_longer_than_max_allowed.prof
68b329da.prof

如果提供了 --profile-svg 选项,则除了 prof 文件和表格输出外,还会生成一个 svg 文件。

$ py.test tests/unit/test_logging.py --profile-svg
...
SVG profile in prof/combined.svg.

最好使用好的 svg 查看器查看,例如 Chrome。

变更日志

1.7.0

  • 全部:支持 pytest >= 4.0.0

  • 全部:支持 Python 3.7

  • pytest-server-fixtures:如果您的机器上未定义主机,则默认为 localhost

  • pytest-server-fixture:由于上游API更改,锁定到 rethinkdb < 2.4.0

  • pytest-verbose-parametrize:添加对改进的标记基础设施的支持

  • pytest-verbose-parametrize:修复集成测试以支持 pytest >= 4.1.0

  • pytest-virtualenv:添加 virtualenv 作为安装要求。修复 #122

  • pytest-webdriver:使用 getfixturevalue 修复 RemovedInPytest4Warning

  • circleci:通过跳过没有推送访问权限的开发者的 coverall 提交来修复检查

  • wheels:生成适用于 python 2.x 和 3.x 的通用 wheels

  • dist:移除构建和分发 *.egg 文件的支持

  • VagrantFile:安装 python 3.7 并默认初始化 python 3.7

  • 使用“logger.warning()”函数修复 DeprecationWarning 警告

1.6.2 (2019-02-21)

  • pytest-server-fixtures:如果调用 kill(),则抑制堆栈跟踪

  • pytest-server-fixtures:修复 TestServerV2 中的随机端口逻辑

1.6.1 (2019-02-12)

  • pytest-server-fixtures:修复在服务器未启动时尝试访问主机名的异常

1.6.0 (2019-02-12)

  • pytest-server-fixtures:添加之前已删除的 TestServerV2.kill() 函数

  • pytest-profiling:在集成测试中锁定 more-itertools==5.0.0,因为它仅适用于 PY3

1.5.1 (2019-01-24)

  • pytest-verbose-parametrize:修复使用 @pytest.mark.parametrize 时出现的 Unicode 参数问题

1.5.0 (2019-01-23)

  • pytest-server-fixtures:使 postgres fixture 和其测试可选,就像所有其他 fixture 一样

  • pytest-server-fixtures:撤销对 pymongo 弃用警告的修复,因为这会破坏与 pymongo 3.6.0 的兼容性

  • pytest-server-fixtures:在 httpd 中停止对 RHEL5 的支持

1.4.1 (2019-01-18)

  • pytest-server-fixtures:现在在 ENV 中指定的服务器二进制路径仅影响服务器类 'thread'

1.4.0 (2019-01-15)

  • 修复 Simple HTTP Server fixture 中的 Python 3 兼容性问题

  • 修复 pytest-profiling 中的损坏测试

  • 锁定 pytest<4.0.0,直到所有弃用警告都得到修复。

  • pytest-webdriver:用无头 Google Chrome 替换弃用的 phantomjs。

  • 将 Vagrantfile 添加到项目中以使测试环境便携。

  • 将 .editorconfig 文件添加到项目中。

  • pytest-server-fixtures:添加具有 Docker 和 Kubernetes 支持的 TestServerV2

  • pytest-server-fixtures:修复 MinioServer 使用后未清理的问题

  • pytest-server-fixtures:修复调用 pymongo 时的弃用警告

  • pytest-server-fixtures:在 MongoTestServer 拆卸时关闭 pymongo 客户端

  • pytest-server-fixtures:将 Mongo、Redis 和 RethinkDB 升级到 TestServerV2

  • coveralls:修复损坏的 coveralls

1.3.1 (2018-06-28)

  • 使用 pymongo list_database_names() 而不是已弃用的 database_names(),添加 pymongo>=3.6.0 依赖项

1.3.0 (2017-11-17)

  • 修复 teardown 为 None 时的工作空间删除问题

  • 修复 pytest-listener 中根记录器的压缩问题

  • 添加 S3 Minio fixture(多谢 Gavin Bisesi)

  • 添加 Postgres fixture(多谢 Gavin Bisesi)

  • 使用 requests 处理服务器 fixture http get,因为它正确处理重定向和代理

1.2.12 (2017-8-1)

  • 修复缓存临时主机名的回归,一些客户端依赖于此。现在这是可选的。

1.2.11 (2017-7-21)

  • 修复 OSX 绑定到非法本地 IP 范围的问题(感谢 Gavin Bisesi)

  • 为 pytest-profiling 设置和 Py3k 修复(感谢 xoviat)

  • 不再尝试在保留本地 IP 主机时绑定端口 5000,因为有人可能将其绑定到 0.0.0.0

  • 修复在本地 venv 未激活时使用 gprof2dot 的 #46 问题

1.2.10 (2017-2-23)

  • 在pytest-webdriver中处理自定义pytest测试项

1.2.9 (2017-2-23)

  • 将用户名添加到mongo服务器临时目录的fixture中,以避免在共享多用户文件系统上的冲突

1.2.8 (2017-2-21)

  • 在shutil.run.run_as_main中返回函数结果

1.2.7 (2017-2-20)

  • 对较旧的path.py版本进行更多处理

  • 允许在pytest-virtualenv中传递virtualenv参数

1.2.6 (2017-2-16 )

  • 更新devpi-server的devpi-server >= 2.0服务器设置

  • 随机选择端口的改进

  • HTTPD服务器现在默认绑定到0.0.0.0以帮助进行Selenium风格的测试

  • 更新mongodb >= 3.2的mongodb服务器参数

  • 对mongodb fixture配置进行纠正并改进启动逻辑

  • 添加了模块作用域的mongodb fixture

  • 对较旧的path.py版本进行处理

  • 修复了#40问题,其中chdir的测试破坏了pytest-profiling

1.2.5 (2016-12-09)

  • 对服务器运行程序的主机和端口生成进行了改进,现在支持随机本地IP

  • 修复了RethinkDB fixture配置的bug

1.2.4 (2016-11-14)

  • 修复了pymongo额外依赖的bug

  • 修复了pytest-virtualenv的Windows兼容性问题(感谢Jean-Christophe Fillion-Robin的PR)

  • 修复了pytest-shutil.cmdline.get_real_python_executable中的符号链接处理

1.2.3 (2016-11-7)

  • 提高了Mongo fixture启动检查的鲁棒性

1.2.2 (2016-10-27)

  • 大多数模块都实现了Python 3兼容性

  • 修复了过时的Path.py导入(感谢Bryan Moscon)

  • 修复了pytest-profiling中过时的multicall(感谢Paul van der Linden的PR)

  • 添加了devpi-server fixture以为每个测试函数创建一个索引

  • 添加了缺失的许可文件

  • 将httpd服务器fixture配置拆分,以便子类更容易覆盖加载的模块

  • 向TestServer基类添加了‘preserve_sys_path’参数,该参数将当前python sys.path导出到子进程中。

  • 更新了httpd、redis和jenkins的运行时参数和路径,以符合当前Ubuntu规范

  • 在拆卸工作空间时忽略错误,以避免shutil.rmtree实现中的竞争条件

1.2.1 (2016-3-1)

  • 修复了pytest-verbose-parametrize以适应最新的pytest版本

1.2.0 (2016-2-19)

  • 新插件:git仓库fixture

1.1.1 (2016-2-16)

  • pytest-profiling改进:在.prof文件中转义非法字符(感谢Aarni Koskela的PR)

1.1.0 (2016-2-15)

  • 新插件:devpi服务器fixture

  • pytest-profiling改进:过长的.prof文件保存为测试名的短哈希(感谢Vladimir Lagunov的PR)

  • 出于安全原因,将workspace.run()的默认行为更改为不使用子shell

  • 修复了virtualenv.run()方法,使其与父方法workspace.run()处理相同的参数

  • 从virtualenv参数中移除了过时的‘–distribute’

1.0.1 (2015-12-23)

  • 打包bug修复

1.0.0 (2015-12-21)

  • 初始公开版本

项目详情


下载文件

为您的平台下载文件。如果您不确定要选择哪个,请了解更多关于安装包的信息。

源分布

pytest-profiling-1.7.0.tar.gz (31.0 kB 查看散列)

上传时间

构建分布

pytest_profiling-1.7.0-py3.6.egg (7.5 kB 查看散列)

上传时间

pytest_profiling-1.7.0-py2.py3-none-any.whl (8.3 kB 查看散列)

上传于 Python 2 Python 3

pytest_profiling-1.7.0-py2.7.egg (7.5 kB 查看哈希值)

上传于 源代码

由以下支持