Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions distributed/tests/test_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1366,21 +1366,19 @@ async def test_register_worker_callbacks_err(c, s, a, b):


@gen_cluster(nthreads=[])
async def test_local_directory(s):
with tmpfile() as fn:
with dask.config.set(temporary_directory=fn):
w = await Worker(s.address)
assert w.local_directory.startswith(fn)
assert "dask-worker-space" in w.local_directory
async def test_local_directory(s, tmp_path):
with dask.config.set(temporary_directory=str(tmp_path)):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit?: I prefer to use os.fsdecode instead of str for pathlib.Path objects

w = await Worker(s.address)
assert w.local_directory.startswith(str(tmp_path))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fun fact: This can be done a little bit nicer by pathlib.Path(w.local_directory) and then using the pathlib https://docs.python.org/3/library/pathlib.html#pathlib.PurePath.is_relative_to if someone can sort out a release of the pathlib2 backport

assert "dask-worker-space" in w.local_directory


@gen_cluster(nthreads=[])
async def test_local_directory_make_new_directory(s):
with tmpfile() as fn:
w = await Worker(s.address, local_directory=os.path.join(fn, "foo", "bar"))
assert w.local_directory.startswith(fn)
assert "foo" in w.local_directory
assert "dask-worker-space" in w.local_directory
async def test_local_directory_make_new_directory(s, tmp_path):
w = await Worker(s.address, local_directory=str(tmp_path / "foo" / "bar"))
assert w.local_directory.startswith(str(tmp_path))
assert "foo" in w.local_directory
assert "dask-worker-space" in w.local_directory


@pytest.mark.skipif(not LINUX, reason="Need 127.0.0.2 to mean localhost")
Expand Down