跟踪资源泄漏的pytest插件。
pytest-leaks的Python项目详细描述
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会话,请在 命令行:
$ cd examples; pytest-3 -v -R : test_faucet.py
=========================== test session starts ===========================
platform linux -- Python 3.7.4, pytest-5.0.1, py-1.8.0, pluggy-0.12.0 --
cachedir: .pytest_cache
rootdir: ..
plugins: leaks-0.3.0
collected 3 items
test_faucet.py::test_leaky_faucet LEAKED [ 33%]
test_faucet.py::test_broken_faucet FAILED [ 66%]
test_faucet.py::test_mended_faucet PASSED [100%]
================================ FAILURES =================================
___________________________ test_broken_faucet ____________________________
def test_broken_faucet():
> assert 0
E assert 0
test_faucet.py:6: AssertionError
============================== leaks summary ==============================
examples/test_faucet.py::test_leaky_faucet: leaked references: [2, 2, 2, 2], memory blocks: [2, 2, 2, 2]
============== 1 failed, 1 passed, 1 leaked in 0.32 seconds ===============
上面使用的测试文件包含以下代码:
$ cat test_faucet.py
drops = []
def test_leaky_faucet():
drops.append({})
def test_broken_faucet():
assert 0
def test_mended_faucet():
assert 1
请注意,pytest leaks多次运行测试:如果您看到测试失败 只有在使用pytest泄漏时才存在,请检查测试是否 不以阻止其运行 第二次。
功能
- 通过反复运行py.test测试和 比较运行之间的总引用计数。
要求
- py.test版本>;=3;
- python的调试版本(2.7或>;=3.5)。
在linux上,python调试版本可以在包pythonX.Y-dbg
中找到。
(Debian和衍生物)和python3-debug
(Fedora和衍生物)。
安装
$ pip install pytest-leaks
贡献
我们非常欢迎您的贡献。测试可以使用 tox请确保覆盖范围 至少在提交请求之前保持不变。
许可证
根据MIT条款和 PSF许可证,“pytest泄漏” 是免费的开源软件。
问题
如果您遇到任何问题,请file an issue 以及详细的描述。
致谢
这个Pytest插件最初是 用Cookiecutter生成 以及@hackebrotCookiecutter-pytest-plugin 模板。