翻译 pytest_collection(session)[source] Perform the collection phase for the given session. Stops at first non-None result, see firstresult: stop at first non-None result. The return value is not used, but only stops further processing. The default collection phase is this (see individual hooks for full details): Starting from session as the initial collector: pytest_collectstart(collector) report = pytest_make_collect_report(collector) pytest_exception_interact(collector, call, report) if an interactive exception occurred For each collected node: If an item, pytest_itemcollected(item) If a collector, recurse into it. pytest_collectreport(report) pytest_collection_modifyitems(session, config, items) pytest_deselected(items) for any deselected items (may be called multiple times) pytest_collection_finish(session) Set session.items to the list of collected items Set session.testscollected to the number of collected items You can implement this hook to only perform some action before collection, for example the terminal plugin uses it to start displaying the collection counter (and returns None). Parameters session (Session) – The pytest session object.
时间: 2024-04-06 11:33:41 浏览: 297
函数 pytest_collection(session) 的作用是执行给定会话的收集阶段。如果有第一个非 None 的结果,函数会停止执行,这受 firstresult 参数的控制。返回值不会被使用,但会停止进一步的处理过程。默认的收集阶段如下(请查看各个钩子的完整细节):
从 session 作为初始收集器开始:
pytest_collectstart(collector)
report = pytest_make_collect_report(collector)
pytest_exception_interact(collector, call, report) 如果发生交互式异常
对于每个收集到的节点:
如果是 item,则执行 pytest_itemcollected(item)
如果是 collector,则递归进入它
pytest_collectreport(report)
pytest_collection_modifyitems(session, config, items)
对于任何已取消选择的项目,执行 pytest_deselected(items)(可能会被多次调用)
pytest_collection_finish(session)
将 session.items 设置为收集到的项目列表
将 session.testscollected 设置为收集到的项目数量
你可以实现这个钩子来只在收集前执行某些操作,例如终端插件使用它来开始显示收集计数器(并返回 None)。
参数 session(Session):pytest 会话对象。
阅读全文