Skip to content

Fix for Verbose mode not having default value on getoption call works on issue #9422 #12706

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

Merged
merged 8 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all 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.get_verbosity() > 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 @@
Example::

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

"""
Expand Down Expand Up @@ -1807,7 +1807,7 @@
session.perform_collect()
invocation_dir = config.invocation_params.dir
tw = _pytest.config.create_terminal_writer(config)
verbose = config.getvalue("verbose")
verbose = config.get_verbosity()

Check warning on line 1810 in src/_pytest/fixtures.py

View check run for this annotation

Codecov / codecov/patch

src/_pytest/fixtures.py#L1810

Added line #L1810 was not covered by tests

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

Check warning on line 1869 in src/_pytest/fixtures.py

View check run for this annotation

Codecov / codecov/patch

src/_pytest/fixtures.py#L1869

Added line #L1869 was not covered by tests

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 @@ -794,7 +794,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 @@ -513,7 +513,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() >= 0 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
Loading