Can any one help with a solution for the following requirement. I have to connect to a VM before starting test suite only once for the entire module. And I am successful with that by using Conftest for that suite.But now, I would like to distribute tests to multiple CPU/cores using Xdist plugin....when I try to do that each of the process runs conftest and I have multiple instances of the connection. Is there a way we can run conftest before starting distribution? or Is there a way to achieve this in any different way?
Asked
Active
Viewed 874 times
1 Answers
1
Are you starting your VM like this?
# contents of conftest.py
def startup_vm():
...
startup_vm()
If that's the case, you can use one of the several plugin hooks available instead. Since you want a hook to execute just once per test session, you can use something like this:
# contents of conftest.py
def startup_vm():
...
def pytest_configure(config):
startup_vm()
def pytest_unconfigure(config):
shutdown_vm()
The full list of plugins is available here:

Bruno Oliveira
- 13,694
- 5
- 43
- 41
-
1Hi, I have a quick question..can I call conftest fixtures in the function called inside pytest.configure?When I could not do it. something like this in conftest. def pytest_configure(config): startup_vm(fixture) As I am trying to install VM through a browser/I need to open url. I would like to use opening url as a fixture so that I can reuse it in other test cases – user3116988 Mar 21 '14 at 22:30