diff --git a/tests/core/test_farmer_harvester_rpc.py b/tests/core/test_farmer_harvester_rpc.py index 431a551b267b..871257d8d3f6 100644 --- a/tests/core/test_farmer_harvester_rpc.py +++ b/tests/core/test_farmer_harvester_rpc.py @@ -40,6 +40,7 @@ from tests.plot_sync.test_delta import dummy_plot from tests.setup_nodes import setup_harvester_farmer, test_constants from tests.time_out_assert import time_out_assert, time_out_assert_custom_interval +from tests.util.misc import assert_rpc_error from tests.util.rpc import validate_get_routes log = logging.getLogger(__name__) @@ -569,14 +570,14 @@ async def assert_added(path: Path) -> None: test_path = Path(root_path / "test_path").resolve() # The test_path doesn't exist at this point - with pytest.raises(ValueError, match=f"Path doesn't exist: {test_path}"): + with assert_rpc_error(f"Path doesn't exist: {test_path}"): await harvester_rpc_client.add_plot_directory(str(test_path)) # Create a file at the test_path and make sure it detects this with open(test_path, "w"): pass - with pytest.raises(ValueError, match=f"Path is not a directory: {test_path}"): + with assert_rpc_error(f"Path is not a directory: {test_path}"): await harvester_rpc_client.add_plot_directory(str(test_path)) # Drop the file, make it a directory and make sure it gets added properly. @@ -585,7 +586,7 @@ async def assert_added(path: Path) -> None: await assert_added(test_path) - with pytest.raises(ValueError, match=f"Path already added: {test_path}"): + with assert_rpc_error(f"Path already added: {test_path}"): await harvester_rpc_client.add_plot_directory(str(test_path)) # Add another one and make sure they are still both there. diff --git a/tests/util/misc.py b/tests/util/misc.py index 42cd20db70ff..d8999b01c591 100644 --- a/tests/util/misc.py +++ b/tests/util/misc.py @@ -13,6 +13,7 @@ from types import TracebackType from typing import Callable, Iterator, List, Optional, Type, Union +import pytest from typing_extensions import final @@ -276,3 +277,10 @@ def __exit__( # decorator, this is just here to retain the function-style naming as the public # interface. Hopefully we can switch away from the class at some point. assert_runtime = _AssertRuntime + + +@contextlib.contextmanager +def assert_rpc_error(error: str) -> Iterator[None]: + with pytest.raises(ValueError) as exception_info: + yield + assert error in exception_info.value.args[0]["error"]