你知道是否有一种方法可以收集所有 pytest 节点 ID(如所示here)使用 pytest python API ?
我已经找到了--collect-only
pytest 的参数,但我不知道如何使用 python 获取输出?
提前致谢 !
如果您想以编程方式访问nodeids,最好是编写一个小插件,将它们存储在测试集合中。例子:
import pytest
class NodeidsCollector:
def pytest_collection_modifyitems(self, items):
self.nodeids = [item.nodeid for item in items]
def main():
collector = NodeidsCollector()
pytest.main(['--collect-only'], plugins=[collector])
# use collector.nodeids now
如果你想避免pytest
输出到终端,另外禁用终端插件:
pytest.main(['--collect-only', '-pno:terminal'], plugins=[collector])
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)