Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests: monkeypatch shutil.get_terminal_size properly #1152

Merged
merged 1 commit into from
Mar 29, 2024

Conversation

hroncok
Copy link
Contributor

@hroncok hroncok commented Mar 26, 2024

The original way led to very confusing internal pytest errors when the test failed.

When the test failed, the original function was not restored, and pytest uses it:

INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/usr/lib/python3.13/site-packages/_pytest/main.py", line 271, in wrap_session
INTERNALERROR>     session.exitstatus = doit(config, session) or 0
INTERNALERROR>                          ~~~~^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/usr/lib/python3.13/site-packages/_pytest/main.py", line 325, in _main
INTERNALERROR>     config.hook.pytest_runtestloop(session=session)
INTERNALERROR>     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/usr/lib/python3.13/site-packages/pluggy/_hooks.py", line 493, in __call__
INTERNALERROR>     return self._hookexec(self.name, self._hookimpls, kwargs, firstresult)
INTERNALERROR>            ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/usr/lib/python3.13/site-packages/pluggy/_manager.py", line 115, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR>            ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/usr/lib/python3.13/site-packages/pluggy/_callers.py", line 152, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>            ~~~~~~~~~~~~~~~~~~^^
INTERNALERROR>   File "/usr/lib/python3.13/site-packages/pluggy/_result.py", line 114, in get_result
INTERNALERROR>     raise exc.with_traceback(exc.__traceback__)
INTERNALERROR>   File "/usr/lib/python3.13/site-packages/pluggy/_callers.py", line 77, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>           ~~~~~~~~~~~~~~~~~~^^^^^^^
INTERNALERROR>   File "/usr/lib/python3.13/site-packages/_pytest/main.py", line 350, in pytest_runtestloop
INTERNALERROR>     item.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem)
INTERNALERROR>     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/usr/lib/python3.13/site-packages/pluggy/_hooks.py", line 493, in __call__
INTERNALERROR>     return self._hookexec(self.name, self._hookimpls, kwargs, firstresult)
INTERNALERROR>            ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/usr/lib/python3.13/site-packages/pluggy/_manager.py", line 115, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR>            ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/usr/lib/python3.13/site-packages/pluggy/_callers.py", line 152, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>            ~~~~~~~~~~~~~~~~~~^^
INTERNALERROR>   File "/usr/lib/python3.13/site-packages/pluggy/_result.py", line 114, in get_result
INTERNALERROR>     raise exc.with_traceback(exc.__traceback__)
INTERNALERROR>   File "/usr/lib/python3.13/site-packages/pluggy/_callers.py", line 77, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>           ~~~~~~~~~~~~~~~~~~^^^^^^^
INTERNALERROR>   File "/usr/lib/python3.13/site-packages/_pytest/runner.py", line 113, in pytest_runtest_protocol
INTERNALERROR>     ihook.pytest_runtest_logstart(nodeid=item.nodeid, location=item.location)
INTERNALERROR>     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/usr/lib/python3.13/site-packages/pluggy/_hooks.py", line 493, in __call__
INTERNALERROR>     return self._hookexec(self.name, self._hookimpls, kwargs, firstresult)
INTERNALERROR>            ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/usr/lib/python3.13/site-packages/pluggy/_manager.py", line 115, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR>            ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/usr/lib/python3.13/site-packages/pluggy/_callers.py", line 113, in _multicall
INTERNALERROR>     raise exception.with_traceback(exception.__traceback__)
INTERNALERROR>   File "/usr/lib/python3.13/site-packages/pluggy/_callers.py", line 77, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>           ~~~~~~~~~~~~~~~~~~^^^^^^^
INTERNALERROR>   File "/usr/lib/python3.13/site-packages/_pytest/terminal.py", line 566, in pytest_runtest_logstart
INTERNALERROR>     self.write_fspath_result(nodeid, "")
INTERNALERROR>     ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^
INTERNALERROR>   File "/usr/lib/python3.13/site-packages/_pytest/terminal.py", line 430, in write_fspath_result
INTERNALERROR>     self._write_progress_information_filling_space()
INTERNALERROR>     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
INTERNALERROR>   File "/usr/lib/python3.13/site-packages/_pytest/terminal.py", line 684, in _write_progress_information_filling_space
INTERNALERROR>     fill = self._tw.fullwidth - w - 1
INTERNALERROR>            ^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/usr/lib/python3.13/site-packages/_pytest/_io/terminalwriter.py", line 86, in fullwidth
INTERNALERROR>     return get_terminal_width()
INTERNALERROR>            ~~~~~~~~~~~~~~~~~~^^
INTERNALERROR>   File "/usr/lib/python3.13/site-packages/_pytest/_io/terminalwriter.py", line 17, in get_terminal_width
INTERNALERROR>     width, _ = shutil.get_terminal_size(fallback=(80, 24))
INTERNALERROR>                ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
INTERNALERROR> TypeError: test_reserved_space_is_integer.<locals>.stub_terminal_size() got an unexpected keyword argument 'fallback'

Description

Checklist

  • I've added this contribution to the changelog.md.
  • I've added my name to the AUTHORS file (or it's already there).

The original way led to very confusing internal pytest errors when the test failed.

When the test failed, the original function was not restored, and pytest uses it:

    INTERNALERROR> Traceback (most recent call last):
    INTERNALERROR>   File "/usr/lib/python3.13/site-packages/_pytest/main.py", line 271, in wrap_session
    INTERNALERROR>     session.exitstatus = doit(config, session) or 0
    INTERNALERROR>                          ~~~~^^^^^^^^^^^^^^^^^
    INTERNALERROR>   File "/usr/lib/python3.13/site-packages/_pytest/main.py", line 325, in _main
    INTERNALERROR>     config.hook.pytest_runtestloop(session=session)
    INTERNALERROR>     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
    INTERNALERROR>   File "/usr/lib/python3.13/site-packages/pluggy/_hooks.py", line 493, in __call__
    INTERNALERROR>     return self._hookexec(self.name, self._hookimpls, kwargs, firstresult)
    INTERNALERROR>            ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    INTERNALERROR>   File "/usr/lib/python3.13/site-packages/pluggy/_manager.py", line 115, in _hookexec
    INTERNALERROR>     return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
    INTERNALERROR>            ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    INTERNALERROR>   File "/usr/lib/python3.13/site-packages/pluggy/_callers.py", line 152, in _multicall
    INTERNALERROR>     return outcome.get_result()
    INTERNALERROR>            ~~~~~~~~~~~~~~~~~~^^
    INTERNALERROR>   File "/usr/lib/python3.13/site-packages/pluggy/_result.py", line 114, in get_result
    INTERNALERROR>     raise exc.with_traceback(exc.__traceback__)
    INTERNALERROR>   File "/usr/lib/python3.13/site-packages/pluggy/_callers.py", line 77, in _multicall
    INTERNALERROR>     res = hook_impl.function(*args)
    INTERNALERROR>           ~~~~~~~~~~~~~~~~~~^^^^^^^
    INTERNALERROR>   File "/usr/lib/python3.13/site-packages/_pytest/main.py", line 350, in pytest_runtestloop
    INTERNALERROR>     item.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem)
    INTERNALERROR>     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    INTERNALERROR>   File "/usr/lib/python3.13/site-packages/pluggy/_hooks.py", line 493, in __call__
    INTERNALERROR>     return self._hookexec(self.name, self._hookimpls, kwargs, firstresult)
    INTERNALERROR>            ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    INTERNALERROR>   File "/usr/lib/python3.13/site-packages/pluggy/_manager.py", line 115, in _hookexec
    INTERNALERROR>     return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
    INTERNALERROR>            ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    INTERNALERROR>   File "/usr/lib/python3.13/site-packages/pluggy/_callers.py", line 152, in _multicall
    INTERNALERROR>     return outcome.get_result()
    INTERNALERROR>            ~~~~~~~~~~~~~~~~~~^^
    INTERNALERROR>   File "/usr/lib/python3.13/site-packages/pluggy/_result.py", line 114, in get_result
    INTERNALERROR>     raise exc.with_traceback(exc.__traceback__)
    INTERNALERROR>   File "/usr/lib/python3.13/site-packages/pluggy/_callers.py", line 77, in _multicall
    INTERNALERROR>     res = hook_impl.function(*args)
    INTERNALERROR>           ~~~~~~~~~~~~~~~~~~^^^^^^^
    INTERNALERROR>   File "/usr/lib/python3.13/site-packages/_pytest/runner.py", line 113, in pytest_runtest_protocol
    INTERNALERROR>     ihook.pytest_runtest_logstart(nodeid=item.nodeid, location=item.location)
    INTERNALERROR>     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    INTERNALERROR>   File "/usr/lib/python3.13/site-packages/pluggy/_hooks.py", line 493, in __call__
    INTERNALERROR>     return self._hookexec(self.name, self._hookimpls, kwargs, firstresult)
    INTERNALERROR>            ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    INTERNALERROR>   File "/usr/lib/python3.13/site-packages/pluggy/_manager.py", line 115, in _hookexec
    INTERNALERROR>     return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
    INTERNALERROR>            ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    INTERNALERROR>   File "/usr/lib/python3.13/site-packages/pluggy/_callers.py", line 113, in _multicall
    INTERNALERROR>     raise exception.with_traceback(exception.__traceback__)
    INTERNALERROR>   File "/usr/lib/python3.13/site-packages/pluggy/_callers.py", line 77, in _multicall
    INTERNALERROR>     res = hook_impl.function(*args)
    INTERNALERROR>           ~~~~~~~~~~~~~~~~~~^^^^^^^
    INTERNALERROR>   File "/usr/lib/python3.13/site-packages/_pytest/terminal.py", line 566, in pytest_runtest_logstart
    INTERNALERROR>     self.write_fspath_result(nodeid, "")
    INTERNALERROR>     ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^
    INTERNALERROR>   File "/usr/lib/python3.13/site-packages/_pytest/terminal.py", line 430, in write_fspath_result
    INTERNALERROR>     self._write_progress_information_filling_space()
    INTERNALERROR>     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
    INTERNALERROR>   File "/usr/lib/python3.13/site-packages/_pytest/terminal.py", line 684, in _write_progress_information_filling_space
    INTERNALERROR>     fill = self._tw.fullwidth - w - 1
    INTERNALERROR>            ^^^^^^^^^^^^^^^^^^
    INTERNALERROR>   File "/usr/lib/python3.13/site-packages/_pytest/_io/terminalwriter.py", line 86, in fullwidth
    INTERNALERROR>     return get_terminal_width()
    INTERNALERROR>            ~~~~~~~~~~~~~~~~~~^^
    INTERNALERROR>   File "/usr/lib/python3.13/site-packages/_pytest/_io/terminalwriter.py", line 17, in get_terminal_width
    INTERNALERROR>     width, _ = shutil.get_terminal_size(fallback=(80, 24))
    INTERNALERROR>                ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
    INTERNALERROR> TypeError: test_reserved_space_is_integer.<locals>.stub_terminal_size() got an unexpected keyword argument 'fallback'
@amjith
Copy link
Member

amjith commented Mar 29, 2024

Thank you!

@amjith amjith merged commit fa4e3db into dbcli:main Mar 29, 2024
3 of 5 checks passed
@parona-source
Copy link
Contributor

parona-source commented Mar 29, 2024

This issue unfortunately now shows up if you invoke pytest with verbose and it will have this error even if it succeeds.

Output
ask@bigglane /home/ask/sources/mycli (main|u=)
 $ python3.11 -m pytest -v  test/test_main.py::test_reserved_space_is_integer
================================================================== test session starts ==================================================================
platform linux -- Python 3.11.8, pytest-7.4.4, pluggy-1.4.0 -- /usr/bin/python3.11
cachedir: .pytest_cache
rootdir: /home/ask/sources/mycli
configfile: pytest.ini
plugins: flaky-3.8.1, asyncio-0.23.6, pytest_httpserver-1.0.10, respx-0.21.1, anyio-4.3.0, pkgcore-0.12.26, xdist-3.5.0
asyncio: mode=Mode.STRICT
collected 1 item                                                                                                                                        

test/test_main.py::test_reserved_space_is_integer PASSED
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/usr/lib/python3.11/site-packages/_pytest/main.py", line 271, in wrap_session
INTERNALERROR>     session.exitstatus = doit(config, session) or 0
INTERNALERROR>                          ^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/usr/lib/python3.11/site-packages/_pytest/main.py", line 325, in _main
INTERNALERROR>     config.hook.pytest_runtestloop(session=session)
INTERNALERROR>   File "/usr/lib/python3.11/site-packages/pluggy/_hooks.py", line 501, in __call__
INTERNALERROR>     return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
INTERNALERROR>            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/usr/lib/python3.11/site-packages/pluggy/_manager.py", line 119, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR>            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/usr/lib/python3.11/site-packages/pluggy/_callers.py", line 181, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>            ^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/usr/lib/python3.11/site-packages/pluggy/_result.py", line 99, in get_result
INTERNALERROR>     raise exc.with_traceback(exc.__traceback__)
INTERNALERROR>   File "/usr/lib/python3.11/site-packages/pluggy/_callers.py", line 102, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>           ^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/usr/lib/python3.11/site-packages/_pytest/main.py", line 350, in pytest_runtestloop
INTERNALERROR>     item.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem)
INTERNALERROR>   File "/usr/lib/python3.11/site-packages/pluggy/_hooks.py", line 501, in __call__
INTERNALERROR>     return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
INTERNALERROR>            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/usr/lib/python3.11/site-packages/pluggy/_manager.py", line 119, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR>            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/usr/lib/python3.11/site-packages/pluggy/_callers.py", line 181, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>            ^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/usr/lib/python3.11/site-packages/pluggy/_result.py", line 99, in get_result
INTERNALERROR>     raise exc.with_traceback(exc.__traceback__)
INTERNALERROR>   File "/usr/lib/python3.11/site-packages/pluggy/_callers.py", line 102, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>           ^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/usr/lib/python3.11/site-packages/flaky/flaky_pytest_plugin.py", line 89, in pytest_runtest_protocol
INTERNALERROR>     self.runner.pytest_runtest_protocol(item, nextitem)
INTERNALERROR>   File "/usr/lib/python3.11/site-packages/_pytest/runner.py", line 114, in pytest_runtest_protocol
INTERNALERROR>     runtestprotocol(item, nextitem=nextitem)
INTERNALERROR>   File "/usr/lib/python3.11/site-packages/_pytest/runner.py", line 133, in runtestprotocol
INTERNALERROR>     reports.append(call_and_report(item, "call", log))
INTERNALERROR>                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/usr/lib/python3.11/site-packages/flaky/flaky_pytest_plugin.py", line 165, in call_and_report
INTERNALERROR>     hook.pytest_runtest_logreport(report=report)
INTERNALERROR>   File "/usr/lib/python3.11/site-packages/pluggy/_hooks.py", line 501, in __call__
INTERNALERROR>     return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
INTERNALERROR>            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/usr/lib/python3.11/site-packages/pluggy/_manager.py", line 119, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR>            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/usr/lib/python3.11/site-packages/pluggy/_callers.py", line 138, in _multicall
INTERNALERROR>     raise exception.with_traceback(exception.__traceback__)
INTERNALERROR>   File "/usr/lib/python3.11/site-packages/pluggy/_callers.py", line 102, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>           ^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/usr/lib/python3.11/site-packages/_pytest/terminal.py", line 622, in pytest_runtest_logreport
INTERNALERROR>     self._write_progress_information_filling_space()
INTERNALERROR>   File "/usr/lib/python3.11/site-packages/_pytest/terminal.py", line 684, in _write_progress_information_filling_space
INTERNALERROR>     fill = self._tw.fullwidth - w - 1
INTERNALERROR>            ^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/usr/lib/python3.11/site-packages/_pytest/_io/terminalwriter.py", line 86, in fullwidth
INTERNALERROR>     return get_terminal_width()
INTERNALERROR>            ^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/usr/lib/python3.11/site-packages/_pytest/_io/terminalwriter.py", line 17, in get_terminal_width
INTERNALERROR>     width, _ = shutil.get_terminal_size(fallback=(80, 24))
INTERNALERROR>                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> TypeError: test_reserved_space_is_integer.<locals>.stub_terminal_size() got an unexpected keyword argument 'fallback'

============================================================= 1 passed, 3 warnings in 0.01s =============================================================
ask@bigglane /home/ask/sources/mycli (main|u=)
 $ echo $?
3
diff --git a/test/test_main.py b/test/test_main.py
index 2a86c13..adaeddf 100644
--- a/test/test_main.py
+++ b/test/test_main.py
@@ -256,10 +256,8 @@ def test_conditional_pager(monkeypatch):
 
 def test_reserved_space_is_integer(monkeypatch):
     """Make sure that reserved space is returned as an integer."""
-    def stub_terminal_size():
-        return (5, 5)
-
-    monkeypatch.setattr(shutil, 'get_terminal_size', stub_terminal_size)
+    monkeypatch.setenv("COLUMNS", "5")
+    monkeypatch.setenv("LINES", "5")
     mycli = MyCli()
     assert isinstance(mycli.get_reserved_space(), int)

Modifying env instead wouldn't such issues at least.

parona-source added a commit to parona-source/mycli that referenced this pull request Mar 29, 2024
* Otherwise this mocked attribute would affect pytest negatively when
  running tests with --verbose.

See-Also: dbcli#1152 (comment)
Signed-off-by: Alfred Wingate <[email protected]>
parona-source added a commit to parona-source/mycli that referenced this pull request Mar 29, 2024
* Otherwise this mocked attribute would affect pytest negatively when
  running tests with --verbose.

See-Also: dbcli#1152 (comment)
Signed-off-by: Alfred Wingate <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants