0

In my conftest.py i have pytest_configuration hook that runs some APIs before executing tests to configure stuff. All is working as expected until i use pytest-xdist to run tests in parallel. In this case, my hook is executed n+1 times, according to the number of nodes i select.

Is there a solution for the problem? I only need the configuration to execute once.

pytest_configuration(config):
    option = config.getoption("--option_to_run_stuff") 
    if option == "1":
        do_stuff()
YuMa
  • 77
  • 5
  • Does this answer your question? https://stackoverflow.com/questions/50151189/pytest-run-around-tests-fixture-to-run-only-once-before-all-tests-in-a-class – Prophet Feb 27 '22 at 15:58
  • Hard to say without much more details, maybe you need to specify scope ? https://pytest-xdist.readthedocs.io/en/latest/how-to.html#making-session-scoped-fixtures-execute-only-once – Gaarv Feb 28 '22 at 08:38
  • Thank you. Ive already solved the issue by changing the approach. Ive simply created a separate script that executes before the session starts. – YuMa Feb 28 '22 at 08:50

0 Answers0