From 72d00b3c7d07b8d916e6e778a15d22875a587df1 Mon Sep 17 00:00:00 2001 From: Jasha <8935917+Jasha10@users.noreply.github.com> Date: Thu, 3 Feb 2022 05:19:53 -0600 Subject: [PATCH] Refactor test_deep_merge: separate test for RuntimeError --- tests/unit/test_utils.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py index 6b0195f..2a8435c 100644 --- a/tests/unit/test_utils.py +++ b/tests/unit/test_utils.py @@ -3,11 +3,9 @@ from typing import Any from typing import Callable from typing import Dict -from typing import Union from unittest.mock import MagicMock from unittest.mock import patch -from _pytest.python_api import RaisesContext from pytest import mark from pytest import param from pytest import raises @@ -139,27 +137,29 @@ def test_absolute_path_not_exist(self) -> None: {1: {2: 4}, 2: 5}, id="nested", ), - param( - {1: 2, 2: 5}, - {1: {3: 4}}, - raises(RuntimeError), - id="merge-dict-into-scalar", - ), ], ) def test_deep_merge( a: Dict[Any, Any], b: Dict[Any, Any], - expected: Union[Dict[Any, Any], RaisesContext[Any]], + expected: Dict[Any, Any], ) -> None: """ Given two dictionaries `a` and `b`, when the `deep_merge` function is invoked with `a` and `b` as arguments, Test that the returned value is as expected. """ - if isinstance(expected, RaisesContext): - with expected: - deep_merge(a, b) - else: - assert deep_merge(a, b) == expected - assert a == expected + assert deep_merge(a, b) == expected + assert a == expected + + +def test_deep_merge_dict_into_scalar() -> None: + """ + Given two incompatible dictionaries `a` and `b`, + when the `deep_merge` function is invoked with `a` and `b` as arguments, + Test that a RuntimeError is raised. + """ + a = {1: 2, 2: 5} + b = {1: {3: 4}} + with raises(RuntimeError): + deep_merge(a, b)