Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog/9422.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix bug where disabling the terminal plugin via ``-p no:terminal`` would cause crashes related to missing the ``verbose`` option.

-- by :user:`GTowers1`
2 changes: 1 addition & 1 deletion doc/en/example/simple.rst
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ display more information if applicable:


def pytest_report_header(config):
if config.getoption("verbose") > 0:
if config.getoption("verbose", 0) > 0:
return ["info1: did you know that ...", "did you?"]

which will add info only when run with "--v":
Expand Down
2 changes: 1 addition & 1 deletion src/_pytest/cacheprovider.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ def get_last_failed_paths(self) -> set[Path]:
return {x for x in result if x.exists()}

def pytest_report_collectionfinish(self) -> str | None:
if self.active and self.config.getoption("verbose") >= 0:
if self.active and self.config.get_verbosity() >= 0:
return f"run-last-failure: {self._report_status}"
return None

Expand Down
2 changes: 1 addition & 1 deletion src/_pytest/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1759,7 +1759,7 @@ def get_verbosity(self, verbosity_type: str | None = None) -> int:
print(config.get_verbosity()) # 1
print(config.get_verbosity(Config.VERBOSITY_ASSERTIONS)) # 2
"""
global_level = self.option.verbose
global_level = self.getoption("verbose", default=0)
assert isinstance(global_level, int)
if verbosity_type is None:
return global_level
Expand Down
6 changes: 3 additions & 3 deletions src/_pytest/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -1348,7 +1348,7 @@ def pytestconfig(request: FixtureRequest) -> Config:
Example::

def test_foo(pytestconfig):
if pytestconfig.getoption("verbose") > 0:
if pytestconfig.get_verbosity() > 0:
...

"""
Expand Down Expand Up @@ -1807,7 +1807,7 @@ def _show_fixtures_per_test(config: Config, session: Session) -> None:
session.perform_collect()
invocation_dir = config.invocation_params.dir
tw = _pytest.config.create_terminal_writer(config)
verbose = config.getvalue("verbose")
verbose = config.get_verbosity()

def get_best_relpath(func) -> str:
loc = getlocation(func, invocation_dir)
Expand Down Expand Up @@ -1866,7 +1866,7 @@ def _showfixtures_main(config: Config, session: Session) -> None:
session.perform_collect()
invocation_dir = config.invocation_params.dir
tw = _pytest.config.create_terminal_writer(config)
verbose = config.getvalue("verbose")
verbose = config.get_verbosity()

fm = session._fixturemanager

Expand Down
2 changes: 1 addition & 1 deletion src/_pytest/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ def pytest_runtestloop(self, session: Session) -> Generator[None, object, object
if session.config.option.collectonly:
return (yield)

if self._log_cli_enabled() and self._config.getoption("verbose") < 1:
if self._log_cli_enabled() and self._config.get_verbosity() < 1:
# The verbose flag is needed to avoid messy test progress output.
self._config.option.verbose = 1

Expand Down
4 changes: 2 additions & 2 deletions src/_pytest/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,12 +435,12 @@ def _repr_failure_py(
else:
style = "long"

if self.config.getoption("verbose", 0) > 1:
if self.config.get_verbosity() > 1:
truncate_locals = False
else:
truncate_locals = True

truncate_args = False if self.config.getoption("verbose", 0) > 2 else True
truncate_args = False if self.config.get_verbosity() > 2 else True

# excinfo.getrepr() formats paths relative to the CWD if `abspath` is False.
# It is possible for a fixture/test to change the CWD while this code runs, which
Expand Down
2 changes: 1 addition & 1 deletion src/_pytest/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ def importtestmodule(
) from e
except ImportError as e:
exc_info = ExceptionInfo.from_current()
if config.getoption("verbose") < 2:
if config.get_verbosity() < 2:
exc_info.traceback = exc_info.traceback.filter(filter_traceback)
exc_repr = (
exc_info.getrepr(style="short")
Expand Down
2 changes: 1 addition & 1 deletion src/_pytest/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def pytest_addoption(parser: Parser) -> None:
def pytest_terminal_summary(terminalreporter: TerminalReporter) -> None:
durations = terminalreporter.config.option.durations
durations_min = terminalreporter.config.option.durations_min
verbose = terminalreporter.config.getvalue("verbose")
verbose = terminalreporter.config.get_verbosity()
if durations is None:
return
tr = terminalreporter
Expand Down
2 changes: 1 addition & 1 deletion src/_pytest/stepwise.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def pytest_runtest_logreport(self, report: TestReport) -> None:
self.lastfailed = None

def pytest_report_collectionfinish(self) -> str | None:
if self.config.getoption("verbose") >= 0 and self.report_status:
if self.config.get_verbosity() and self.report_status:
return f"stepwise: {self.report_status}"
return None

Expand Down
7 changes: 7 additions & 0 deletions testing/acceptance_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1486,3 +1486,10 @@ def my_fixture(self, request):
raise AssertionError(
f"pytest command failed:\n{exc.stdout=!s}\n{exc.stderr=!s}"
) from exc


def test_no_terminal_plugin(pytester: Pytester) -> None:
"""Smoke test to ensure pytest can execute without the terminal plugin (#9422)."""
pytester.makepyfile("def test(): assert 1 == 2")
result = pytester.runpytest("-pno:terminal", "-s")
assert result.ret == ExitCode.TESTS_FAILED
2 changes: 1 addition & 1 deletion testing/python/approx.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def report_failure(self, out, test, example, got):

@contextmanager
def temporary_verbosity(config, verbosity=0):
original_verbosity = config.getoption("verbose")
original_verbosity = config.getoption("verbose", 0)
config.option.verbose = verbosity
try:
yield
Expand Down
2 changes: 1 addition & 1 deletion testing/test_assertrewrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def f() -> None:
msg = getmsg(f)
assert msg is not None
line = msg.splitlines()[0]
if request.config.getoption("verbose") > 1:
if request.config.getoption("verbose", 0) > 1:
assert line == (
"assert '12345678901234567890123456789012345678901234567890A' "
"== '12345678901234567890123456789012345678901234567890B'"
Expand Down