1

Pytest setup_method executes before xdist worker_id fixture is it possible to get worker id before start of setup_method?

e.g. I have:

Content of conftest.py:

@pytest.fixture(autouse=True)
def worker_id(request):
    print("worker")
    if hasattr(request.config, 'slaveinput'):
        request.config.worker = request.config.slaveinput['slaveid']
    else:
        request.config.worker = "master"
    return request.config.worker

Content of test.py:

class TestSomething:

    def setup_method(self):
        print("setup")

    def test_something(self):
        print("test")

And the output is:

setup
worker
test
galoget
  • 722
  • 9
  • 15
Vadim Kovrizhkin
  • 1,575
  • 4
  • 16
  • 27
  • 2
    This is the known [bug](https://github.com/pytest-dev/pytest/issues/517) for pytest. You can use fixture in place of setup method. – Chanda Korat Feb 28 '18 at 09:15

1 Answers1

0

How you are getting worker_id ?

suppose we launched 4 process using pytest -n 4 now four process were launched named pw[0], pw[1], pw[2] & pw[3].

I would allocate user1 credentials to process1 and user2 credentials to process2 based on name that pw[0] & pw[1]

Is it possible to implement

  • 1
    Yes def pytest_configure(config): if hasattr(config, 'slaveinput'): config.worker = config.slaveinput['slaveid'] allocate_user(config.worker) else: config.worker = 'master' http://take.ms/ARMN2 – Vadim Kovrizhkin Mar 08 '18 at 13:26