Do you know if there is a way to collect all pytest node ids (as presented here) using the pytest python API ?
I have found the --collect-only parameter of pytest, but I can't figure out how to get the output using python ?
Thanks in advance !
If you want to access nodeids programmatically, best is to write a small plugin that will store them on test collection. Example:
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
If you want to avoid pytest output to the terminal, disable the terminal plugin in addition:
pytest.main(['--collect-only', '-pno:terminal'], plugins=[collector])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With