1

I have a set of 200 unit tests which do run ok when executed on a single thread with py.test.

I do have a fixture which is configuring a webserver so I can run the tests against it.

Still, I need to be sure that this is run only once before all the other tests are executed, if this fails the entire process must be stopped. If this succeeds, it can perform the testing on as many threads it wants.

How can I achieve that?

Cœur
  • 37,241
  • 25
  • 195
  • 267
sorin
  • 161,544
  • 178
  • 535
  • 806

1 Answers1

1

Currently, you have to implement this outside of pytest-xdist as it provides no means to co-ordinate "whole testrun" fixtures. Maybe starting a script that uses file-locking and only executes the starting of a service once. As to pytest-xdist, there is discussion here about a testrun fixture: https://bitbucket.org/hpk42/pytest/issue/252/allow-fixtures-to-execute-only-once-per

hpk42
  • 21,501
  • 4
  • 47
  • 53
  • Wow, this renders pytest-xdist totally useless to me because, I cannot afford to customise the entire execution model for tests, it will break travis-ci, tox usage, PyCharm IDE will not know how to run the tests and so on. Also, I do really like the idea ok keeping things simple, or making them simple if they are not. Simple things do not break as much as the complex ones, especially hacks. – sorin Jul 21 '14 at 07:53
  • Can this not be done using the `pytest_configure()` hook right now? Or does that also get executed in the xdist nodes? – flub Aug 04 '14 at 12:10
  • maybe i am misunderstanding the poster. You can use ``pytest_configure(config)`` and check if the ``config.slaveinput`` attribute exists in which case you are on a slave. In the absence of it you are on the master and could start subprocesses and pass on information about the URL etc. to the subprocesses. This post http://holgerkrekel.net/2013/11/12/running-tests-against-multiple-devicesresources-in-parallel/ explains the mechanics of passing data to slave nodes a bit. – hpk42 Aug 05 '14 at 13:48