Dask分布式.utils_test.client不继承父流程环境变量吗?

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

我正在使用pytest来测试我敏捷的工作流程。我有一个特定的工作流程ingest_l0_files,它使用Client将任务映射到工作人员。在测试过程中,我需要人为设置目录路径,该目录路径是在名为CURRENT_RUN_LOG_PATH的环境变量中设置的。重要的是,此设置在集成测试和实际运行中可以完美地工作。我在驱动程序脚本中设置了环境变量,并且我的所有工作人员都可以访问该环境变量(因为它们大概是从您的主进程生成的)。但是,在我的pytest中,(人工设置的)环境变量对工作人员不可用。为什么?也许我可以告诉utils_test.client重新初始化其环境,然后将其传递给其工作人员?

from distributed.utils_test import client
def test_ingest_l0_files(client, clean_database_fixture, tmpdir):
    """Test the workflow function `ingest_l0_files`"""
    os.putenv('CURRENT_RUN_LOG_PATH', f'{tmpdir}')
    get_config('CURRENT_RUN_LOG_PATH')
    client = client()
    unique_obs = workflow.ingest_l0_files([L0_ALL_FILE, L0_LPT_FILE], client)
    assert len(unique_obs) == 20
    os.unsetenv('CURRENT_RUN_LOG_PATH')
pytest dask dask-distributed
1个回答
0
投票

您是正确的,client pytest固定装置不是特别可扩展。

如果您对异步编程感到满意,那么我建议使用@gen_cluster装饰器,它提供了更多选择:

@gen_cluster(
    client=True,
    Worker=Nanny,
    worker_options={"env": {"FOO": "BAR"}},
)
async def test_foo(client, scheduler, worker_a, worker_b):
    await ...

但是这要求您的代码是异步友好的,但实际情况可能并非如此。如果您调用非异步方法,则此测试将无济于事。]

https://distributed.dask.org/en/latest/develop.html#writing-tests

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