py.test的扭曲插件。

pytest-twisted的Python项目详细描述


PyPI versionSupported Python versionsTravis build statusAppVeyor build statusBlack code style

Authors:Ralf Schmitt, Kyle Altendorf, Victor Titor
Version:1.11
Date:2019-08-20
Download:https://pypi.python.org/pypi/pytest-twisted#downloads
Code:https://github.com/pytest-dev/pytest-twisted

pytest twisted是pytest的一个插件,它允许测试代码, 它使用了扭曲的框架。测试函数可以返回延迟的 对象和pytest将使用此插件等待其完成。

安装

使用以下命令安装插件:

pip install pytest-twisted

使用插件

插件在安装后可用,可以使用 -p no:twisted

默认情况下,twisted.internet.default用于安装反应器。 这将创建与^{tt3}相同的反应器$ 会的。可使用^{tt4}指定替代反应器$ 选项目前支持qt5reactor与^{tt6}一起使用$ 以及pytest-qtasyncio。这个guide描述了如何添加 支持一个新的反应堆。

反应堆在第一次测试前自动创建,但可以 通过调用 pytest_twisted.init_default_reactor()或相应的函数 用于所需的备用反应堆。

在诸如 一个名为pytest_twistedconftest.py文件 被pytest检测为未知钩子是不应该的。一种选择 是import pytest_twisted as pt

内联回调

使用twisted.internet.defer.inlineCallbacks作为测试的装饰符 使用fixture的函数不起作用。请使用 pytest_twisted.inlineCallbacks取而代之:

@pytest_twisted.inlineCallbacks
def test_some_stuff(tmpdir):
    res = yield threads.deferToThread(os.listdir, tmpdir.strpath)
    assert res == []

确保

使用twisted.internet.defer.ensureDeferred作为测试的装饰符 使用fixture的函数不起作用。请使用 pytest_twisted.ensureDeferred取而代之:

@pytest_twisted.ensureDeferred
async def test_some_stuff(tmpdir):
    res = await threads.deferToThread(os.listdir, tmpdir.strpath)
    assert res == []

等待设备延迟

pytest_twisted.blockon允许装置等待延迟:

@pytest.fixture
def val():
    d = defer.Deferred()
    reactor.callLater(1.0, d.callback, 10)
    return pytest_twisted.blockon(d)

扭曲的绿色

有些图书馆(如corotwine)需要知道greenlet,即 运行扭曲的反应堆。它可以从 twisted_greenlet固定装置。以下代码可用于 Corotwine与Pytest Twisted一起工作:

@pytest.fixture(scope="session", autouse=True)
def set_MAIN(request, twisted_greenlet):
    from corotwine import protocol
    protocol.MAIN = twisted_greenlet

差不多就这些了。

折旧

v1.9

pytest.blockon
使用pytest_twisted.blockon
pytest.inlineCallbacks
使用pytest_twisted.inlineCallbacks

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
使用多个参数的枚举   从Oracle到Redis的java复制表   java如何保护tomcat服务器中的db用户名和密码。xml   java如何使用注册密钥保护移动应用程序?   java在什么情况下超类不应该是抽象的?   java Backspace键在macOS上的Scala REPL中不起作用   arduino Java+Uno+RFID:调用方法读取Java中的RFID   带有where语句中集合的java JPA查询   java如何向基于Tyrus注释的客户端添加请求头   java对我的二进制搜索算法的反馈   java重新访问数据库时文件的内容不正确   用户在字符串中输入值后退出While循环(Java)   java如何在Maven中的多个项目之间共享项目依赖关系?   java Close从未在数据库上被明确调用   在java中从文件读入布尔矩阵   Java:如何使用父节点将XML流拆分为小型XML文档。VTDXML