'*shorten test outputs by storing them in files in DIR and*',
'*returning just the first/last few lines. disable by*',
'*using --shorten-output-dir=""*',
+ '*--shorten-output-lines=LINES*',
+ '*change the number of lines shown by the*',
+ '*--shorten-output-dir option*',
])
def do_stdout_stderr_check(testdir, additional_args, stdout_lines,
- stderr_lines, enabled):
- # type: (pytest.Testdir, list[str], int, int, bool) -> pytest.RunResult
+ stderr_lines, enabled, line_limit):
+ # type: (pytest.Testdir, list[str], int, int, bool, int) -> pytest.RunResult
testdir.makepyfile(test_print=f"""
import sys
lines = ['*--- Captured stdout call ---*']
hr = '-' * 50
- if enabled and stdout_lines >= 2 * _DEFAULT_LINE_LIMIT:
+ if enabled and stdout_lines >= line_limit:
trimmed_msg = ("Output Trimmed, Full output in: "
"test-out/test_print_py/test_print/call-stdout.txt")
lines.append(trimmed_msg)
lines.append(hr)
- for i in range(_DEFAULT_LINE_LIMIT):
+ for i in range((line_limit + 1) // 2):
lines.append(f'in stdout {i}')
lines.append(hr)
lines.append(trimmed_msg)
lines.append(hr)
- for i in range(stdout_lines - _DEFAULT_LINE_LIMIT, stdout_lines):
+ for i in range(stdout_lines - line_limit // 2, stdout_lines):
lines.append(f'in stdout {i}')
lines.append(hr)
lines.append(trimmed_msg)
for i in range(stdout_lines):
lines.append(f'in stdout {i}')
lines.append('*--- Captured stderr call ---*')
- if enabled and stderr_lines >= 2 * _DEFAULT_LINE_LIMIT:
+ if enabled and stderr_lines >= line_limit:
trimmed_msg = ("Output Trimmed, Full output in: "
"test-out/test_print_py/test_print/call-stderr.txt")
lines.append(trimmed_msg)
lines.append(hr)
- for i in range(_DEFAULT_LINE_LIMIT):
+ for i in range((line_limit + 1) // 2):
lines.append(f'in stderr {i}')
lines.append(hr)
lines.append(trimmed_msg)
lines.append(hr)
- for i in range(stderr_lines - _DEFAULT_LINE_LIMIT, stderr_lines):
+ for i in range(stderr_lines - line_limit // 2, stderr_lines):
lines.append(f'in stderr {i}')
lines.append(hr)
lines.append(trimmed_msg)
shorten-output-dir = test-out
""")
- do_stdout_stderr_check(testdir, [], 1, 1, True)
+ do_stdout_stderr_check(testdir, [], 1, 1, True,
+ line_limit=_DEFAULT_LINE_LIMIT)
def test_nothing(testdir):
# type: (pytest.Testdir) -> None
- do_stdout_stderr_check(testdir, [], 1, 1, False)
+ do_stdout_stderr_check(testdir, [], 1, 1, False,
+ line_limit=_DEFAULT_LINE_LIMIT)
def test_arg(testdir):
# type: (pytest.Testdir) -> None
do_stdout_stderr_check(
- testdir, ["--shorten-output-dir=test-out"], 1, 1, True)
+ testdir, ["--shorten-output-dir=test-out"], 1, 1, True,
+ line_limit=_DEFAULT_LINE_LIMIT)
def test_arg_override_ini(testdir):
""")
do_stdout_stderr_check(
- testdir, ["--shorten-output-dir="], 1, 1, False)
+ testdir, ["--shorten-output-dir="], 1, 1, False,
+ line_limit=_DEFAULT_LINE_LIMIT)
def test_disable_capture(testdir):
def test_20k_disabled(testdir):
# type: (pytest.Testdir) -> None
- do_stdout_stderr_check(testdir, [], 20000, 20000, False)
+ do_stdout_stderr_check(testdir, [], 20000, 20000, False,
+ line_limit=_DEFAULT_LINE_LIMIT)
def test_20k(testdir):
# type: (pytest.Testdir) -> None
do_stdout_stderr_check(
- testdir, ["--shorten-output-dir=test-out"], 20000, 20000, True)
+ testdir, ["--shorten-output-dir=test-out"], 20000, 20000, True,
+ line_limit=_DEFAULT_LINE_LIMIT)
def test_21k(testdir):
# type: (pytest.Testdir) -> None
do_stdout_stderr_check(
- testdir, ["--shorten-output-dir=test-out"], 21000, 21000, True)
+ testdir, ["--shorten-output-dir=test-out"], 21000, 21000, True,
+ line_limit=_DEFAULT_LINE_LIMIT)
def test_22k(testdir):
# type: (pytest.Testdir) -> None
do_stdout_stderr_check(
- testdir, ["--shorten-output-dir=test-out"], 22000, 22000, True)
+ testdir, ["--shorten-output-dir=test-out"], 22000, 22000, True,
+ line_limit=_DEFAULT_LINE_LIMIT)
-def test_1x(testdir):
+def test_half(testdir):
# type: (pytest.Testdir) -> None
- lines = _DEFAULT_LINE_LIMIT
+ lines = _DEFAULT_LINE_LIMIT // 2
do_stdout_stderr_check(
- testdir, ["--shorten-output-dir=test-out"], lines, lines, True)
+ testdir, ["--shorten-output-dir=test-out"], lines, lines, True,
+ line_limit=_DEFAULT_LINE_LIMIT)
-def test_50_percent_more(testdir):
+def test_75_percent(testdir):
# type: (pytest.Testdir) -> None
- lines = _DEFAULT_LINE_LIMIT + _DEFAULT_LINE_LIMIT // 2
+ lines = _DEFAULT_LINE_LIMIT * 3 // 4
do_stdout_stderr_check(
- testdir, ["--shorten-output-dir=test-out"], lines, lines, True)
+ testdir, ["--shorten-output-dir=test-out"], lines, lines, True,
+ line_limit=_DEFAULT_LINE_LIMIT)
-def test_2x_minus_two(testdir):
+def test_limit_minus_two(testdir):
# type: (pytest.Testdir) -> None
- lines = _DEFAULT_LINE_LIMIT * 2 - 2
+ lines = _DEFAULT_LINE_LIMIT - 2
do_stdout_stderr_check(
- testdir, ["--shorten-output-dir=test-out"], lines, lines, True)
+ testdir, ["--shorten-output-dir=test-out"], lines, lines, True,
+ line_limit=_DEFAULT_LINE_LIMIT)
-def test_2x_minus_one(testdir):
+def test_limit_minus_one(testdir):
# type: (pytest.Testdir) -> None
- lines = _DEFAULT_LINE_LIMIT * 2 - 1
+ lines = _DEFAULT_LINE_LIMIT - 1
do_stdout_stderr_check(
- testdir, ["--shorten-output-dir=test-out"], lines, lines, True)
+ testdir, ["--shorten-output-dir=test-out"], lines, lines, True,
+ line_limit=_DEFAULT_LINE_LIMIT)
-def test_2x(testdir):
+def test_limit(testdir):
# type: (pytest.Testdir) -> None
- lines = _DEFAULT_LINE_LIMIT * 2
+ lines = _DEFAULT_LINE_LIMIT
do_stdout_stderr_check(
- testdir, ["--shorten-output-dir=test-out"], lines, lines, True)
+ testdir, ["--shorten-output-dir=test-out"], lines, lines, True,
+ line_limit=_DEFAULT_LINE_LIMIT)
-def test_2x_plus_one(testdir):
+def test_limit_plus_one(testdir):
# type: (pytest.Testdir) -> None
- lines = _DEFAULT_LINE_LIMIT * 2 + 1
+ lines = _DEFAULT_LINE_LIMIT + 1
do_stdout_stderr_check(
- testdir, ["--shorten-output-dir=test-out"], lines, lines, True)
+ testdir, ["--shorten-output-dir=test-out"], lines, lines, True,
+ line_limit=_DEFAULT_LINE_LIMIT)
-def test_2x_plus_two(testdir):
+def test_limit_plus_two(testdir):
# type: (pytest.Testdir) -> None
- lines = _DEFAULT_LINE_LIMIT * 2 + 2
+ lines = _DEFAULT_LINE_LIMIT + 2
do_stdout_stderr_check(
- testdir, ["--shorten-output-dir=test-out"], lines, lines, True)
+ testdir, ["--shorten-output-dir=test-out"], lines, lines, True,
+ line_limit=_DEFAULT_LINE_LIMIT)
def test_1M(testdir):
# type: (pytest.Testdir) -> None
lines = 1_000_000
do_stdout_stderr_check(
- testdir, ["--shorten-output-dir=test-out"], lines, lines, True)
+ testdir, ["--shorten-output-dir=test-out"], lines, lines, True,
+ line_limit=_DEFAULT_LINE_LIMIT)
+
+
+def test_small_limit_minus_one(testdir):
+ # type: (pytest.Testdir) -> None
+ line_limit = 50
+ lines = line_limit - 1
+ do_stdout_stderr_check(testdir,
+ ["--shorten-output-dir=test-out",
+ f"--shorten-output-lines={line_limit}"],
+ lines, lines, True, line_limit=line_limit)
+
+
+def test_small_limit(testdir):
+ # type: (pytest.Testdir) -> None
+ line_limit = 50
+ lines = line_limit
+ do_stdout_stderr_check(testdir,
+ ["--shorten-output-dir=test-out",
+ f"--shorten-output-lines={line_limit}"],
+ lines, lines, True, line_limit=line_limit)
+
+
+def test_small_limit_plus_one(testdir):
+ # type: (pytest.Testdir) -> None
+ line_limit = 50
+ lines = line_limit + 1
+ do_stdout_stderr_check(testdir,
+ ["--shorten-output-dir=test-out",
+ f"--shorten-output-lines={line_limit}"],
+ lines, lines, True, line_limit=line_limit)
+
+
+def test_large_limit_minus_one(testdir):
+ # type: (pytest.Testdir) -> None
+ line_limit = 200
+ lines = line_limit - 1
+ do_stdout_stderr_check(testdir,
+ ["--shorten-output-dir=test-out",
+ f"--shorten-output-lines={line_limit}"],
+ lines, lines, True, line_limit=line_limit)
+
+
+def test_large_limit(testdir):
+ # type: (pytest.Testdir) -> None
+ line_limit = 200
+ lines = line_limit
+ do_stdout_stderr_check(testdir,
+ ["--shorten-output-dir=test-out",
+ f"--shorten-output-lines={line_limit}"],
+ lines, lines, True, line_limit=line_limit)
+
+
+def test_large_limit_plus_one(testdir):
+ # type: (pytest.Testdir) -> None
+ line_limit = 200
+ lines = line_limit + 1
+ do_stdout_stderr_check(testdir,
+ ["--shorten-output-dir=test-out",
+ f"--shorten-output-lines={line_limit}"],
+ lines, lines, True, line_limit=line_limit)
if __name__ == "__main__":