You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
worker_id will never be a falsey value to satisfy the if not worker_id check. If tests are not running in distributed workers, worker_id will be set to master.
If worker_id == 'master' guarantees that tests are not running in distributed workers, then one should just change not worker_id to worker_id == 'master'.
Otherwise, the worker_id fixture should be changed (or another fixture should be added) to distinguish between a non-distributed master node and a distributed master node.
Alternatively, we can not special case the master node and just do something like
@pytest.fixture(scope="session")
def session_data(tmp_path_factory, worker_id):
- if not worker_id:- # not executing in with multiple workers, just produce the data and let- # pytest's fixture caching do its job- return produce_expensive_data()-- # get the temp directory shared for by all workers- root_tmp_dir = tmp_path_factory.getbasetemp().parent+ tmp_dir = tmp_path_factory.getbasetemp()+ root_tmp_dir = tmp_dir if worker_id == 'master' else tmp_dir.parent
fn = root_tmp_dir / "data.json"
with FileLock(str(fn) + ".lock"):
if fn.is_file():
data = json.loads(fn.read_text())
else:
data = produce_expensive_data()
fn.write_text(json.dumps(data))
return data
The text was updated successfully, but these errors were encountered:
If worker_id == 'master' guarantees that tests are not running in distributed workers, then one should just change not worker_id to worker_id == 'master'.
This is the correct one: when distributing tests, the master node will never execute any tests, so it is not possible for worker_id be "master" when distributing tests. I'm fixing that in #582.
https://github.com/pytest-dev/pytest-xdist/blob/master/README.rst#making-session-scoped-fixtures-execute-only-once
worker_id
will never be a falsey value to satisfy theif not worker_id
check. If tests are not running in distributed workers,worker_id
will be set tomaster
.https://github.com/pytest-dev/pytest-xdist/blob/master/src/xdist/plugin.py#L221-L233
I'm not sure what the correct solution is here.
worker_id == 'master'
guarantees that tests are not running in distributed workers, then one should just changenot worker_id
toworker_id == 'master'
.worker_id
fixture should be changed (or another fixture should be added) to distinguish between a non-distributed master node and a distributed master node.The text was updated successfully, but these errors were encountered: