Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handy API to know information about master/slaves from session #504

Closed
smarie opened this issue Feb 14, 2020 · 2 comments · Fixed by #505
Closed

Handy API to know information about master/slaves from session #504

smarie opened this issue Feb 14, 2020 · 2 comments · Fixed by #505

Comments

@smarie
Copy link
Contributor

smarie commented Feb 14, 2020

As mentioned in smarie/python-pytest-harvest#36 (and discussed already with @nicoddemus in smarie/python-pytest-harvest#32) it would be great to have an elegant API to answer these simple questions:

  • get_xdist_worker_id(session): would return session.config.slaveinput['slaveid'] or raise an exception if this not an xdist worker
  • is_xdist_worker(session): would return True if this is an xdist worker, False otherwise
  • is_xdist_master(session): would return True if this is the xdist master, False otherwise (important: this would return False when distribution has not been activated and "normal" pytest has been run on a single process)

Would you like a PR for this ?

When/if this API is done, we should not forget to post the answer on this SO question

@smarie smarie changed the title Handy API to know Handy API to know information about master/slaves from session Feb 14, 2020
@smarie
Copy link
Contributor Author

smarie commented Feb 17, 2020

Implementation note : is_xdist_master could rely on the second environment variable listed in the doc:

  • PYTEST_XDIST_WORKER: the name of the worker, e.g., "gw2".
  • PYTEST_XDIST_WORKER_COUNT: the total number of workers in this session, e.g., "4" when -n 4 is given in the command-line.

PYTEST_XDIST_WORKER_COUNT seems to be a viable way to disambiguate between no distribution and master node with distribution. To check

smarie pushed a commit to smarie/pytest-xdist that referenced this issue Feb 18, 2020
@smarie
Copy link
Contributor Author

smarie commented Feb 18, 2020

Update: actually a better way was just to check at request_or_session.config.option.dist != "no".

I'll push a PR in a minute

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant