我正在为我的一个项目开发一个使用pytest的测试套件。由于项目的性质,我需要创建一个Pytest插件来控制测试的运行方式;测试不是在本地运行,而是发送到另一个进程运行。(我知道xdist,但我认为它不能解决我的问题。)
通过重写各种pytest_runtest_*方法,我一直在编写自己的Pytest插件。到目前为止进展顺利。这里是我遇到麻烦的地方:我希望pytest_runtest_setup、pytest_runtest_call和pytest_runtest_teardown的实现真正负责设置、调用和解压。他们会在不同的过程中做这件事。我的问题是:在Pytest调用我的pytest_runtest_setup之后,也调用了所有其他的插件。这是因为pytest_runtest_setup的钩子规范有firstresult=False。
我不想这样做,因为我不希望pytest_runtest_setup在当前进程上实际运行。我想自己负责管理它。我想要重写的运行方式,而不是添加到其中。我希望运行下面的pytest_runtest_setup的其他实现来运行而不是。
我该怎么做?
发布于 2016-08-08 07:14:55
通用“runtest”钩子
所有与运行测试相关的钩子都接收一个pytest.Item对象。
Pytest_runtest_protocol(项目,附件)源
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(项目)源
called before pytest_runtest_call(item).Pytest_runtest_call(项目)源
called to execute the test item.Pytest_runtest_teardown(项目,附件)源
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(项目,呼叫)源
return a _pytest.runner.TestReport object for the given pytest.Item and _pytest.runner.CallInfo.为了更深入地理解,您可以查看_pytest.runner中这些钩子的默认实现,也可以在_pytest.pdb中查看这些钩子的默认实现,后者与_pytest.capture及其输入/输出捕获交互,以便在发生测试失败时立即进入交互式调试。
报告的_pytest.terminal专门使用报告钩子打印有关测试运行的信息。
https://stackoverflow.com/questions/38667429
复制相似问题