From 692d37e98d8f815944da721dafc578c767e306c9 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 | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/test_main.py b/test/test_main.py index 2a86c13b..589d6cd7 100644 --- a/test/test_main.py +++ b/test/test_main.py @@ -259,9 +259,10 @@ def test_reserved_space_is_integer(monkeypatch): def stub_terminal_size(): return (5, 5) - monkeypatch.setattr(shutil, 'get_terminal_size', stub_terminal_size) - mycli = MyCli() - assert isinstance(mycli.get_reserved_space(), int) + with monkeypatch.context() as m: + m.setattr(shutil, 'get_terminal_size', stub_terminal_size) + mycli = MyCli() + assert isinstance(mycli.get_reserved_space(), int) def test_list_dsn():