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

Add ini option "assert_truncate_level" #63

Merged
merged 2 commits into from
Nov 3, 2019
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
5 changes: 4 additions & 1 deletion src/_pytest/assertion/truncate.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ def _should_truncate_item(item):
"""
Whether or not this test item is eligible for truncation.
"""
level = item.config.getini("assert_truncate_level")
verbose = item.config.option.verbose
return verbose < 2 and not _running_on_ci()
if level == "auto":
return verbose < 2 and not _running_on_ci()
return int(level) > verbose


def _running_on_ci():
Expand Down
12 changes: 12 additions & 0 deletions src/_pytest/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,17 @@ def pytest_addoption(parser):
default="progress",
)

# Experimental.
parser.addini(
"assert_truncate_level",
help=(
"Truncate explanations of assertion failures? "
'("auto" (when verbosity < 2, and not running on CI), '
"or minimum verbosity level to trigger it (i.e. 0 for no truncation)."
),
default="auto",
)


def pytest_configure(config):
reporter = TerminalReporter(config, sys.stdout)
Expand Down Expand Up @@ -1032,6 +1043,7 @@ def short_test_summary(self) -> None:
if not self.reportchars:
return

# NOTE: there's also _pytest.assertion._running_on_ci.
if os.environ.get("CI") == "true" or not self.isatty:
termwidth = None
else:
Expand Down
10 changes: 10 additions & 0 deletions testing/test_assertion.py
Original file line number Diff line number Diff line change
Expand Up @@ -946,6 +946,16 @@ def test_many_lines():
]
)

# test assert_truncate_level ini option.
result = testdir.runpytest("-o", "assert_truncate_level=1")
result.stdout.fnmatch_lines(
["E ...Full output truncated (2 lines hidden), use '-vv' to show"]
)
result = testdir.runpytest("-o", "assert_truncate_level=0")
result.stdout.fnmatch_lines(["* 6*"])
result = testdir.runpytest("-v", "-o", "assert_truncate_level=0")
result.stdout.fnmatch_lines(["* 6*"])

result = testdir.runpytest("-vv")
result.stdout.fnmatch_lines(["* 6*"])

Expand Down