I want to write a pytest
session finish hook that is aware if the xdist plugin has been activated (for example if the -n
option has been passed). Is there an official / stable way to do this ? I found a way to identify if this is a xdist worker, but not to disambiguate between the xdist master and the 'main' pytest process when xdist is deactivated.
def pytest_sessionfinish(session):
try:
pytest_worker_id = session.config.slaveinput['slaveid']
except AttributeError:
# TODO disambiguate: are we the xdist master node or the "main" pytest node with xdist deactivated?
...
Note: this is to get rid of the try/except in this conftest.py example
Thanks in advance ! Kind regards