From 86a994c1327de5868994cdc706c46d2783dcb105 Mon Sep 17 00:00:00 2001 From: Alfred Wingate Date: Fri, 29 Mar 2024 12:47:15 +0200 Subject: [PATCH] Tests: Use monkeypatch.context to avoid side effects on pytest * Otherwise this mocked attribute would affect pytest negatively when running tests with --verbose. See-Also: https://github.com/dbcli/mycli/pull/1152#issuecomment-2027036256 Signed-off-by: Alfred Wingate --- test/test_main.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/test_main.py b/test/test_main.py index 2a86c13b..c2a54444 100644 --- a/test/test_main.py +++ b/test/test_main.py @@ -259,7 +259,8 @@ def test_reserved_space_is_integer(monkeypatch): def stub_terminal_size(): return (5, 5) - monkeypatch.setattr(shutil, 'get_terminal_size', stub_terminal_size) + with monkeypatch.context() as m: + m.setattr(shutil, 'get_terminal_size', stub_terminal_size) mycli = MyCli() assert isinstance(mycli.get_reserved_space(), int)