跳转到主要内容

一个用于追踪资源泄漏的pytest插件。

项目描述

pytest-leaks - 一个pytest插件,用于追踪资源泄漏

See Package Info on PyPI See Build Status on Travis CI See Build Status on AppVeyor

一个用于追踪资源泄漏的pytest插件。

用法

leaks:
  -R LEAKS, --leaks=LEAKS
                        runs each test several times and examines
                        sys.gettotalrefcount() to see if the test appears to
                        be leaking references. The argument should be of the
                        form stab:run where 'stab' is the number of times the
                        test is run to let gettotalrefcount settle down, 'run'
                        is the number of times further it is run. These
                        parameters all have defaults (5 and 4, respectively),
                        and the minimal invocation is '-R :'.

要将泄漏测试添加到您的py.test会话,请在命令行上添加-R选项

$ python3-debug -mpytest -v -R : examples/test_faucet.py
=========================== test session starts ===========================
platform linux -- Python 3.7.5, pytest-5.3.1, py-1.8.0, pluggy-0.13.1 -- .
cachedir: .pytest_cache
rootdir: .
plugins: leaks-0.3.1
collected 4 items

examples/test_faucet.py::test_leaky_faucet LEAKED                   [ 25%]
examples/test_faucet.py::test_broken_faucet FAILED                  [ 50%]
examples/test_faucet.py::test_mended_faucet PASSED                  [ 75%]
examples/test_faucet.py::test_skip_marker_example LEAKED            [100%]

================================ FAILURES =================================
___________________________ test_broken_faucet ____________________________

    def test_broken_faucet():
>       assert 0
E       assert 0

examples/test_faucet.py:8: AssertionError
============================== leaks summary ==============================
examples/test_faucet.py::test_leaky_faucet: leaked references: [2, 2, 2, 2], memory blocks: [2, 2, 2, 2]
examples/test_faucet.py::test_skip_marker_example: leaked (not checked): 'not testing'
================== 1 failed, 1 passed, 2 leaked in 0.50s ==================

请注意,必须使用Python的调试构建。上面使用的测试文件包含以下代码

$ cat test_faucet.py
import pytest

drops = []
def test_leaky_faucet():
    drops.append({})

def test_broken_faucet():
    assert 0

def test_mended_faucet():
    assert 1

@pytest.mark.no_leak_check(fail=True, reason="not testing")
def test_skip_marker_example():
    pass

请注意,pytest-leaks会多次运行测试:如果您看到只有在使用pytest-leaks时才出现的测试失败,请检查测试是否以防止其再次运行的方式修改了任何全局状态。

功能

  • 通过重复运行pytest测试并比较运行之间的总引用计数来检测内存泄漏。

需求

  • pytest版本 >= 3;
  • Python(2.7或>=3.5)的调试构建。

在Linux上,Python调试构建可以在以下软件包中找到:pythonX.Y-dbg(Debian及其衍生版)和python3-debug(Fedora及其衍生版)。

安装

您可以通过pipPyPI安装"pytest-leaks"。

$ pip install pytest-leaks

贡献

我们非常欢迎贡献。可以使用tox运行测试,请在提交拉取请求之前确保覆盖率至少保持不变。

许可

MITPSF许可协议下发布,“pytest-leaks”是免费和开源软件。

问题

如果您遇到任何问题,请附带详细描述提交问题

项目详情


下载文件

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

源分布

pytest-leaks-0.3.1.tar.gz (18.6 kB 查看哈希值)

上传时间

由以下支持