跳过主要内容

pytest的固定配置工具

项目描述

Py.test固定配置的简单对象。允许在所需的配置变量未设置时跳过测试。

安装

使用您喜欢的包管理器安装

pip install pytest-fixture-config
#  or..
easy_install pytest-fixture-config

在您的测试或conftest.py中显式启用固定配置(当使用setuptools入口点时不需要)

pytest_plugins = ['pytest_fixture_config']

指定配置

要指定您的变量,您在插件模块中的某个位置创建一个类,并创建一个读取变量的单例实例。在这个示例中,我们从shell环境读取它们

import os
from pytest_fixture_config import Config

class FixtureConfig(Config):
    __slots__ = ('log_dir', 'log_watcher')

CONFIG=FixtureConfig(
    log_dir=os.getenv('LOG_DIR', '/var/log'),       # This has a default
    log_watcher=os.getenv('LOG_WATCHER'),           # This does not
)

使用配置

在运行时简单地在您的固定配置中引用单例

import pytest

@pytest.fixture
def log_watcher():
    return subprocess.popen([CONFIG.log_watcher, '--log-dir', CONFIG.log_dir])

def test_log_watcher(watcher):
    watcher.communicate()

在缺少某些内容时跳过测试

有一些装饰器允许你在设置未设置时跳过测试。这在测试你可能没有安装但不想让测试套件失败的东西时很有用。

from pytest_fixture_config import requires_config

@pytest.fixture
@requires_config(CONFIG, ['log_watcher', 'log_dir'])
def log_watcher():
    return subprocess.popen([CONFIG.log_watcher, '--log-dir', CONFIG.log_dir])

还有一个yield_fixtures的版本。

from pytest_fixture_config import yield_requires_config

@pytest.fixture
@yield_requires_config(CONFIG, ['log_watcher', 'log_dir'])
def log_watcher():
    watcher = subprocess.popen([CONFIG.log_watcher, '--log-dir', CONFIG.log_dir])
    yield watcher
    watcher.kill()

变更日志

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:添加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 Server固定中的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中的根记录器压缩问题

  • 添加了S3 Minio固定(多谢Gavin Bisesi)

  • 添加了Postgres固定(多谢Gavin Bisesi)

  • 使用requests对服务器固定http get,因为它可以正确处理重定向和代理

1.2.12 (2017-8-1)

  • 修复了缓存临时主机名的回归,一些客户端依赖于它。现在这是可选的。

1.2.11 (2017-7-21)

  • 修复了OSX绑定到非法本地IP范围的问题(多谢Gavin Bisesi)

  • 为pytest-profiling设置和Py3k修复(多谢xoviat)

  • 当保留本地IP主机时,我们不再尝试绑定端口5000,因为有人可能将其绑定到0.0.0.0

  • 修复了当本地venv未激活时源gprof2dot的问题

1.2.10 (2017-2-23)

  • 在pytest-webdriver中处理自定义Pytest测试项

1.2.9 (2017-2-23)

  • 将用户名添加到mongo服务器固定tempdir路径中,以防止在共享多用户文件系统上发生冲突

1.2.8 (2017-2-21)

  • 在shutil.run.run_as_main中返回函数结果

1.2.7 (2017-2-20)

  • 更多对older versions of path.py的处理

  • 允许在pytest-virtualenv中传递virtualenv参数

1.2.6 (2017-2-16 )

  • 更新devpi服务器设置以支持devpi-server >= 2.0

  • 对随机端口选择进行改进

  • HTTPD服务器现在默认绑定到0.0.0.0,以帮助Selenium-style测试

  • 更新mongodb服务器参数以支持mongodb >= 3.2

  • 修正mongodb配置文件并改进启动逻辑

  • 添加了模块作用域的mongodb配置文件

  • 处理path.py旧版本的兼容性

  • 修复#40问题,该问题中更改工作目录的测试会导致pytest-profiling崩溃

1.2.5 (2016-12-09)

  • 改进服务器运行器主机和端口生成,现在支持随机本地IP

  • 修复RethinkDB配置文件的错误

1.2.4 (2016-11-14)

  • 修复pymongo额外依赖的错误

  • 修复pytest-virtualenv在Windows上的兼容性问题(感谢Jean-Christophe Fillion-Robin的贡献)

  • 修复pytest-shutil.cmdline.get_real_python_executable的符号链接处理

1.2.3 (2016-11-7)

  • 提高Mongo配置文件启动检查的鲁棒性

1.2.2 (2016-10-27)

  • 大多数模块的Python 3兼容性

  • 修复了过时的Path.py导入(感谢Bryan Moscon)

  • 修复了pytest-profiling中过时的multicall(感谢Paul van der Linden的贡献)

  • 添加devpi-server配置文件以创建每个测试函数的索引

  • 添加了缺失的许可文件

  • 将httpd服务器配置文件拆分,以便子类可以更容易地覆盖加载的模块

  • 将“preserve_sys_path”参数添加到TestServer基类中,该参数将当前Python sys.path导出到子进程中。

  • 更新httpd、redis和jenkins的运行时参数和路径,以符合当前的Ubuntu规范

  • 在销毁工作空间时忽略错误,以避免shutil.rmtree实现中的竞争条件

1.2.1 (2016-3-1)

  • 修复pytest-verbose-parametrize以兼容最新的pytest版本

1.2.0 (2016-2-19)

  • 新插件:git存储库配置文件

1.1.1 (2016-2-16)

  • pytest-profiling改进:在.prof文件中转义非法字符(感谢Aarni Koskela的贡献)

1.1.0 (2016-2-15)

  • 新插件:devpi服务器配置文件

  • pytest-profiling改进:过长的.prof文件被保存为测试名称的短哈希(感谢Vladimir Lagunov的贡献)

  • 出于安全原因,将workspace.run()的默认行为更改为不使用子shell

  • 修复virtualenv.run()方法,使其与父方法workspace.run()处理参数相同

  • 从virtualenv参数中删除了过时的“–distribute”

1.0.1 (2015-12-23)

  • 包装错误修复

1.0.0 (2015-12-21)

  • 首次公开发布

项目详情


下载文件

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

源分布

pytest-fixture-config-1.7.0.tar.gz (9.9 kB 查看哈希)

上传时间:

构建的分布

pytest_fixture_config-1.7.0-py3.6.egg (5.7 kB 查看哈希)

上传时间:

pytest_fixture_config-1.7.0-py2.py3-none-any.whl (6.5 kB 查看哈希)

上传时间: Python 2 Python 3

pytest_fixture_config-1.7.0-py2.7.egg (5.7 kB 查看哈希)

上传时间:

支持者