diff --git a/distributed/cli/tests/test_dask_scheduler.py b/distributed/cli/tests/test_dask_scheduler.py index 06303458eac..a92e9b4a090 100644 --- a/distributed/cli/tests/test_dask_scheduler.py +++ b/distributed/cli/tests/test_dask_scheduler.py @@ -475,6 +475,11 @@ def test_version_option(): assert result.exit_code == 0 +@pytest.mark.filterwarnings( + "ignore" + ":The profiler was enabled in .* running the profiler in tests is not recommended" + ":RuntimeWarning" +) @pytest.mark.slow def test_idle_timeout(): start = time() @@ -483,8 +488,8 @@ def test_idle_timeout(): distributed.cli.dask_scheduler.main, ["--idle-timeout", "1s"] ) stop = time() - assert 1 < stop - start < 10 assert result.exit_code == 0 + assert 1 < stop - start < 10 @pytest.mark.slow diff --git a/distributed/core.py b/distributed/core.py index 45c9c95e5f2..1163f0ce8e4 100644 --- a/distributed/core.py +++ b/distributed/core.py @@ -3,6 +3,7 @@ import asyncio import inspect import logging +import os import sys import threading import traceback @@ -356,6 +357,15 @@ def __init__( if not hasattr(self.io_loop, "profile"): if dask.config.get("distributed.worker.profile.enabled"): + current_test = os.environ.get("PYTEST_CURRENT_TEST") + if current_test: + warnings.warn( + f"The profiler was enabled in {current_test}." + " running the profiler in tests is not recommended.", + RuntimeWarning, + stacklevel=2, + ) + ref = weakref.ref(self.io_loop) def stop() -> bool: