py.test的virtualenv fixture
项目描述
在测试中创建Python虚拟环境,并在拆卸时清理。该fixture具有安装包和列出已安装内容的实用方法。
安装
使用您最喜欢的包安装程序进行安装
pip install pytest-virtualenv
# or
easy_install pytest-virtualenv
在您的测试或conftest.py中显式启用fixture(当使用setuptools入口点时不需要)
pytest_plugins = ['pytest_virtualenv']
配置
此fixture使用以下环境变量进行配置
设置 |
描述 |
默认 |
---|---|---|
VIRTUALENV_FIXTURE_EXECUTABLE |
将使用哪个virtualenv可执行文件来创建新的venvs |
virtualenv |
Fixture属性
以下是一个简单的测试用例,用于展示基本配置属性。有关 path.py 的更多信息,请参阅 https://pathpy.readthedocs.io/
def test_virtualenv(virtualenv):
# the 'virtualenv' attribute is a `path.py` object for the root of the virtualenv
dirnames = virtualenv.virtualenv.dirs()
assert {'bin', 'include', 'lib'}.intersection(set(dirnames))
# the 'python' attribute is a `path.py` object for the python executable
assert virtualenv.python.endswith('/bin/python')
安装包
您可以通过名称安装包并查询已安装的内容。
def test_installing(virtualenv):
virtualenv.install_package('coverage', installer='pip')
# installed_packages() will return a list of `PackageEntry` objects.
assert 'coverage' in [i.name for i in virtualenv.installed_packages()]
开发源代码检查
使用 python setup.py develop 在 测试运行器的 python 环境中(即,与 py.test 安装相同的运行时)设置的任何包作为源代码检查,将被检测为这样的包,并且可以使用 install_package 通过名称安装。默认情况下,它们使用 python setup.py develop 安装到虚拟环境中,同时还有一个选项来构建和安装 egg 文件。
def test_installing_source(virtualenv):
# Install a source checkout of my_package as an egg file
virtualenv.install_package('my_package', build_egg=True)
运行命令
测试配置有一个 run 方法,它允许您运行命令,就像您首先激活虚拟环境一样,设置了正确的路径。
def test_run(virtualenv):
python_exe_path = virtualenv.python
runtime_exe = virtualenv.run("python -c 'import sys; print sys.executable'", capture=True)
assert runtime_exe == python_exe_path
使用覆盖率运行命令
测试配置有一个 run_with_coverage 方法,它类似于 run,但在虚拟环境内部运行命令。这对于捕获在正常测试运行环境之外被测试的工具的测试覆盖率非常有用。
def test_coverage(virtualenv):
# You will have to install coverage first
virtualenv.install_package(coverage)
virtualenv.run_with_coverage(["my_entry_point", "--arg1", "--arg2"])
变更日志
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:添加虚拟环境作为安装要求。修复 #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 配置和其测试可选,就像所有其他配置一样
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 服务器配置中的 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中修复了根日志记录器的固定squash
添加了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范围的bug(感谢Gavin Bisesi)
为pytest-profiling设置和Py3k修复(感谢xoviat)
不再尝试绑定端口5000以保留本地IP主机,因为有人可能已经将其绑定到0.0.0.0
修复了#46号问题,在本地venv未激活时源码gprof2dot
1.2.10 (2017-2-23)
在pytest-webdriver中处理自定义Pytest测试项
1.2.9 (2017-2-23)
将用户名添加到mongo服务器fixture的tempdir路径中,以防止在共享多用户文件系统上发生冲突
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服务器设置以兼容devpi-server >= 2.0
随机端口选择改进
HTTPD服务器现在默认绑定到0.0.0.0以帮助Selenium风格的测试
更新mongodb服务器参数以兼容mongodb >= 3.2
对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的symlink处理
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以兼容最新的py.test版本
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-virtualenv-1.7.0.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 2270ee8822111ec25db48e9d9f2efec32e68483a015b14cd0d92aeccc6ff820f |
|
MD5 | 6e5edf102ef8bb00c902a4ea15be83ae |
|
BLAKE2b-256 | 9673f3d34462e1d2de89bab407ba3dac5212e9e6996f5b4bc3c6930c68f51b62 |
pytest-virtualenv-1.7.0-py3.6.egg 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 8113bc38845754849fc2411bf6ca9eb91d98685246b0c71c2fbd17e747ec0055 |
|
MD5 | 34f11bfb89f873fd21d76278272abf70 |
|
BLAKE2b-256 | 615d816fc0f082f7271f034074a8e124e947e305a6b03adf42360eabf77fb8f8 |
pytest-virtualenv-1.7.0-py2.py3-none-any.whl 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | fee44d423701d6ab550b202aa8e45ccda77bfe8e72c4318a8f43e6af553ad502 |
|
MD5 | 1171dd6df3f59162c4584a8240e8a3c4 |
|
BLAKE2b-256 | 217f0ec1ab9b8fcd4a3a063b97143a97d1c093d01227353b682c9027d14b14c2 |
pytest-virtualenv-1.7.0-py2.7.egg 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | d350c739956df963914729d14790bde1c6ba4fa9fcf2b78eb77151925f68c7a9 |
|
MD5 | 6140be6d483cf6d0467c4a43a521b086 |
|
BLAKE2b-256 | c36bc4e259c8fcd4241e2fa980ad21d790ba2b482de168c6a783a5e3fd5bef14 |