config/argparsing: use our own get_terminal_width()

This commit is contained in:
Ran Benita 2020-04-30 14:20:48 +03:00
parent bafc9bd58b
commit 414a87a53f
3 changed files with 5 additions and 2 deletions

View File

@ -1,6 +1,8 @@
from .terminalwriter import get_terminal_width
from .terminalwriter import TerminalWriter from .terminalwriter import TerminalWriter
__all__ = [ __all__ = [
"TerminalWriter", "TerminalWriter",
"get_terminal_width",
] ]

View File

@ -15,6 +15,7 @@ from typing import Union
import py import py
import _pytest._io
from _pytest.compat import TYPE_CHECKING from _pytest.compat import TYPE_CHECKING
from _pytest.config.exceptions import UsageError from _pytest.config.exceptions import UsageError
@ -466,7 +467,7 @@ class DropShorterLongHelpFormatter(argparse.HelpFormatter):
def __init__(self, *args: Any, **kwargs: Any) -> None: def __init__(self, *args: Any, **kwargs: Any) -> None:
"""Use more accurate terminal width via pylib.""" """Use more accurate terminal width via pylib."""
if "width" not in kwargs: if "width" not in kwargs:
kwargs["width"] = py.io.get_terminal_width() kwargs["width"] = _pytest._io.get_terminal_width()
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
def _format_action_invocation(self, action: argparse.Action) -> str: def _format_action_invocation(self, action: argparse.Action) -> str:

View File

@ -1253,7 +1253,7 @@ def test_help_formatter_uses_py_get_terminal_width(monkeypatch):
formatter = DropShorterLongHelpFormatter("prog") formatter = DropShorterLongHelpFormatter("prog")
assert formatter._width == 90 assert formatter._width == 90
monkeypatch.setattr("py.io.get_terminal_width", lambda: 160) monkeypatch.setattr("_pytest._io.get_terminal_width", lambda: 160)
formatter = DropShorterLongHelpFormatter("prog") formatter = DropShorterLongHelpFormatter("prog")
assert formatter._width == 160 assert formatter._width == 160