首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Pytest插件:覆盖pytest_runtest_call和朋友

Pytest插件:覆盖pytest_runtest_call和朋友
EN

Stack Overflow用户
提问于 2016-07-29 21:01:09
回答 1查看 3.8K关注 0票数 8

我正在为我的一个项目开发一个使用pytest的测试套件。由于项目的性质,我需要创建一个Pytest插件来控制测试的运行方式;测试不是在本地运行,而是发送到另一个进程运行。(我知道xdist,但我认为它不能解决我的问题。)

通过重写各种pytest_runtest_*方法,我一直在编写自己的Pytest插件。到目前为止进展顺利。这里是我遇到麻烦的地方:我希望pytest_runtest_setuppytest_runtest_callpytest_runtest_teardown的实现真正负责设置、调用和解压。他们会在不同的过程中做这件事。我的问题是:在Pytest调用我的pytest_runtest_setup之后,也调用了所有其他的插件。这是因为pytest_runtest_setup的钩子规范有firstresult=False

我不想这样做,因为我不希望pytest_runtest_setup在当前进程上实际运行。我想自己负责管理它。我想要重写的运行方式,而不是添加到其中。我希望运行下面的pytest_runtest_setup的其他实现来运行而不是

我该怎么做?

EN

回答 1

Stack Overflow用户

发布于 2016-08-08 07:14:55

通用“runtest”钩子

所有与运行测试相关的钩子都接收一个pytest.Item对象。

Pytest_runtest_protocol(项目,附件)源

代码语言:javascript
复制
implements the runtest_setup/call/teardown protocol for the given test item, including capturing exceptions and calling reporting hooks.
Parameters: 

    item – test item for which the runtest protocol is performed.
    nextitem – the scheduled-to-be-next test item (or None if this is the end my friend). This argument is passed on to pytest_runtest_teardown().

Return boolean: 

True if no further hook implementations should be invoked.

Pytest_runtest_setup(项目)源

代码语言:javascript
复制
called before pytest_runtest_call(item).

Pytest_runtest_call(项目)源

代码语言:javascript
复制
called to execute the test item.

Pytest_runtest_teardown(项目,附件)源

代码语言:javascript
复制
called after pytest_runtest_call.
Parameters: nextitem – the scheduled-to-be-next test item (None if no further test item is scheduled). This argument can be used to perform exact teardowns, i.e. calling just enough finalizers so that nextitem only needs to call setup-functions.

Pytest_runtest_makereport(项目,呼叫)源

代码语言:javascript
复制
return a _pytest.runner.TestReport object for the given pytest.Item and _pytest.runner.CallInfo.

为了更深入地理解,您可以查看_pytest.runner中这些钩子的默认实现,也可以在_pytest.pdb中查看这些钩子的默认实现,后者与_pytest.capture及其输入/输出捕获交互,以便在发生测试失败时立即进入交互式调试。

报告的_pytest.terminal专门使用报告钩子打印有关测试运行的信息。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38667429

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档