Pytest-parallel lib. How to get worker id like in pytest-xdist?

160 views Asked by At

Now when using pytest-parallel lib the worker_id could not be found by this plugin since (a guess) this is only xdist compatible fixture to get worker id.

`@pytest.fixture(scope='session')
def driver_path_lock(selenium_config: SeleniumConfig, tmp_path_factory, worker_id) -> str:
    """
    Downloads the webdriver and caches it for a session
    """
    if worker_id == "master":
        print("install driver worker id = master")
        return install_driver(selenium_config)
    root_tmp_dir = tmp_path_factory.getbasetemp().parent
    fn = root_tmp_dir / "data.json"
    with FileLock(f"{str(fn)}.lock"):
        if fn.is_file():
            data = json.loads(fn.read_text())
        else:
            data = install_driver(selenium_config)
            fn.write_text(json.dumps(data))
    print(f"return data {data}")
    return data`

Initially I tried to make pytest cache the webdriver using session scoped driver caching. It worked fine until tests were run in parallel. The prallel runner ignores session scope and runs fixtures as it were function scoped. Very little info could be found regarding session scoped parallel execution but I could only find pytest-xdist solution using FileLock. pytest-xdist docs. How do you get the process id in pytest-parallel?

0

There are 0 answers