Pytest setup_method在xdist worker_id fixture之前执行

问题描述 投票:0回答:1

Pytest setup_methodxdist worker_id夹具之前执行是否有可能在setup_method开始之前获得工人ID?

例如我有:

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

test.py的内容:

class TestSomething:

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

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

输出是:

setup
worker
test
python pytest xdist
1个回答
0
投票

你是如何得到worker_id的?

假设我们使用pytest -n 4启动了4个进程,现在启动了4个进程,名为pw [0],pw [1],pw [2]&pw [3]。

我会根据pw [0]&pw [1]的名称将user1凭据分配给process1和user2凭据到process2

是否可以实施

© www.soinside.com 2019 - 2024. All rights reserved.