本文档提供有关开发gevent本身的信息,包括有关运行测试的信息。
更多信息在 CONTRIBUTING.rst
记录在gevent存储库的根目录中。
开发gevent需要能够从源代码安装gevent。见 从源安装 有关这方面的一般信息。
建议将gevent的开发副本安装到 virtual environment ;您可以使用 venv
与python 3一起分发的模块,或 virtualenv ,可能与 virtualenvwrapper .
对于要使用的每个Python实现和版本,您可能需要不同的虚拟环境。GEvent包括 tox 用于跨多个Python版本自动化测试过程的配置,但这可能很慢。
本文的其余部分将假定在独立的虚拟环境中工作,但通常不会在提示中显示这一点。创建虚拟环境的示例如下:
$ python3 -m venv gevent-env
$ cd gevent-env
$ . bin/activate
(gevent-env) $
要处理gevent,我们需要获取源代码,安装gevent的依赖项,包括测试依赖项,并将gevent安装为 editable install 使用PIP -e option
(also known as development mode ,这与跑步基本相同 python setup.py develop
)
获取源意味着克隆git存储库:
(gevent-env) $ git clone https://github.com/gevent/gevent.git
(gevent-env) $ cd gevent
安装gevent的依赖项、测试依赖项和gevent本身可以通过安装 dev-requirements.txt
文件::
(gevent-env) $ pip install -r dev-requirements.txt
警告
此PIP命令不适用于PIP 19.1。使用PIP 19.0或更低版本,或使用PIP 19.1.1 --no-use-pep517
. 见 issue 1412 .
GEvent有一个广泛的回归测试套件,使用标准实现 unittest
模块。它使用 custom testrunner
它提供了增强的测试隔离(对猴子补丁很重要),并行运行测试,并处理其他特定于GEvent的异常。
测试运行程序有许多选项:
$ python -mgevent.tests --help
Traceback (most recent call last):
File "/home/bk/usr/python37/lib/python3.7/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/home/bk/usr/python37/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/bk/usr/vpy_rst_x/lib/python3.7/site-packages/gevent/tests/__main__.py", line 5, in <module>
from gevent.testing import testrunner
File "/home/bk/usr/vpy_rst_x/lib/python3.7/site-packages/gevent/testing/__init__.py", line 86, in <module>
from .leakcheck import ignores_leakcheck
File "/home/bk/usr/vpy_rst_x/lib/python3.7/site-packages/gevent/testing/leakcheck.py", line 28, in <module>
import objgraph
ModuleNotFoundError: No module named 'objgraph'
运行所有测试的最简单方法就是调用测试运行程序,通常是从源代码签出的根目录调用:
(gevent-env) $ python -mgevent.tests
Running tests in parallel with concurrency 7
...
Ran 3107 tests (skipped=333) in 132 files in 01:52
您还可以使用测试运行程序运行单个gevent测试文件:
(gevent-env) $ python -m gevent.tests test__util.py
Running tests in parallel with concurrency 1
+ /.../python -u -mgevent.tests.test__util
- /.../python -u -mgevent.tests.test__util [Ran 9 tests in 1.1s]
Longest-running tests:
1.1 seconds: /.../python -u -mgevent.tests.test__util
Ran 9 tests in 1 files in 1.1s
或者你可以运行一个猴子补丁的标准库测试:
(gevent-env) $ python -m gevent.tests.test___monkey_patching test_socket.py
Running tests in parallel with concurrency 1
+ /.../python -u -W ignore -m gevent.testing.monkey_test test_socket.py
Running with patch_all(Event=False): test_socket.py
Added imports 1
Skipped testEmptyFileSend (1)
...
Ran 555 tests in 23.042s
OK (skipped=172)
- /.../python -u -W ignore -m gevent.testing.monkey_test test_socket.py [took 26.7s]
Longest-running tests:
26.7 seconds: /.../python -u -W ignore -m gevent.testing.monkey_test test_socket.py
Ran 0 tests in 1 files in 00:27
一些TestRunner选项具有等效的环境变量。尤其是, --quiet
是 GEVENTTEST_QUIET
和 -u
是 GEVENTTEST_USE_RESOURCES
.
在提交pull请求之前,最好在所有支持的Python版本上运行测试,并使用prospector检查代码质量。这就是在Travis CI上所做的。局部可使用毒性:
pip install tox
tox
这是在CI上完成的,因此通常不需要在本地完成。
测试运行程序接受 --coverage
参数以通过 coverage.py 包裹。就像这样:
python -m gevent.tests --coverage
coverage combine
coverage html -i
<open htmlcov/index.html>
gevent支持标准库测试套件的资源。默认情况下启用所有资源。禁用资源将禁用使用这些资源的测试。例如,要禁用访问外部网络(Internet)的测试,请禁用 network
资源。可以选择:
$ python -m gevent.tests -u-network
环境变量:
$ GEVENTTEST_USE_RESOURCES=-network python -m gevent.tests
为提交的每个推拉请求运行一个测试套件。Travis CI用于在Linux上进行测试,以及 AppVeyor 在Windows上运行生成。
基于Travis CI自动将更新提交到 coveralls.io 监控测试覆盖率。
注解
在Debian上,您可能需要 libpythonX.Y-testsuite
已安装以运行所有测试。
注解
这是GEvent维护人员的半组织注释集合。
释放GEvent时使用 zest.releaser . 一般流程如下:
将所有相关更改推送到master。
从gevent工作副本,运行 prerelease
. 解决它带来的任何问题。让它碰到版本号(或输入正确的版本号)并提交。
跑 release
. 让它创建标记并提交它;让它创建一个sdist,但是 不 让它上传。
把标签和主机推到Github。
让Appveyor构建标记。从那个版本下载所有构建的轮子。最简单的方法是用内德·巴切尔德的 appveyor-download.py script .
同时,旋转Docker并从gevent checkout run的根目录 scripts/releases/make-manylinux
. 这就产生了轮子 wheelhouse/
.
如果在Mac电脑上, cd scripts/releases && ./geventreleases.sh
. 这就产生了轮子 /tmp/gevent/
.
使用将appveyor、manylinux和mac轮子上载到pypi twine
. 还要确保上传SDIST!
跑 postrelease
,让它触发版本并将更改推送到GitHub。
Next page: 成功案例