一个用于追踪资源泄漏的pytest插件。
项目描述
pytest-leaks - 一个pytest插件,用于追踪资源泄漏
一个用于追踪资源泄漏的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及其衍生版)。
安装
您可以通过pip从PyPI安装"pytest-leaks"。
$ pip install pytest-leaks
贡献
我们非常欢迎贡献。可以使用tox运行测试,请在提交拉取请求之前确保覆盖率至少保持不变。
许可
在MIT和PSF许可协议下发布,“pytest-leaks”是免费和开源软件。
问题
如果您遇到任何问题,请附带详细描述提交问题。
项目详情
关闭
pytest-leaks-0.3.1.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 42ef79f8e889b943724be7f208accb179d0ec0c26a0426ac19ab98ec4d2b7eda |
|
MD5 | 8597476e95a05b52a94258bf0fe3941c |
|
BLAKE2b-256 | b9bdb904495f16decf0b74f8afd8bba6075986def3f56cc70e4e13e4611c9088 |