Skip to content

Commit

Permalink
Tests: Tweak per-test log to de-duplicate output
Browse files Browse the repository at this point in the history
Deduplicate output between phases so it is not repeated.
(Previous phase output was repeated in the log.)
Fix isseu with "/" in test name.
  • Loading branch information
jakub-vavra-cz committed Feb 13, 2024
1 parent 895b462 commit 8a7b37e
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/tests/multihost/sssd/testlib/common/custom_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def __init__(self, config: pytest.Config) -> None:
if self.log_per_test not in ["never", "duplicate"]:
self.config.option.showlocals = True
self.config.option.reportchars = 'a'
self.config.option.tbstyle = 'line'
self.config.option.tbstyle = 'long'
self.config.option.showcapture = 'no'
self.config.option.capture = 'fd'

Expand All @@ -39,7 +39,7 @@ def _write_log(self, test: str, phases: list = None) -> None:
tr = self.tests[test]
test_name = test.split("::")[-1]
test_name = test_name.translate(
str.maketrans('":<>|*? [', "---------", "]()"))
str.maketrans('":<>|*? [/', "----------", "]()"))
logdir = os.path.join(os.path.dirname(self.config.option.log_file),
'logs')
os.makedirs(logdir, exist_ok=True)
Expand All @@ -50,17 +50,27 @@ def _write_log(self, test: str, phases: list = None) -> None:
# We do not fail on missing phase as 'call'
# could be missing when setup failed.
continue
skip_out = skip_err = skip_log = 0
if phase == 'call':
skip_out = len(tr['setup'].capstdout)
skip_err = len(tr['setup'].capstderr)
skip_log = len(tr['setup'].caplog)
elif phase == 'teardown':
skip_out = len(tr['setup'].capstdout) + len(tr['call'].capstdout)
skip_err = len(tr['setup'].capstderr) + len(tr['call'].capstderr)
skip_log = len(tr['setup'].caplog) + len(tr['call'].caplog)

f.write(f"\nPHASE: {phase.upper()} for {test_name}"
f"... [{tr[phase].outcome.upper()}]\n")
if tr[phase].capstdout:
f.write(f"\n=== {test_name} {phase.upper()} OUT ===\n")
f.write(tr[phase].capstdout)
f.write(tr[phase].capstdout[skip_out:])
if tr[phase].capstderr:
f.write(f"\n=== {test_name} {phase.upper()} ERR ===\n")
f.write(tr[phase].capstderr)
f.write(tr[phase].capstderr[skip_err:])
if tr[phase].caplog:
f.write(f"\n=== {test_name} {phase.upper()} LOG ===\n")
f.write(tr[phase].caplog)
f.write(tr[phase].caplog[skip_log:])
if tr[phase].longreprtext:
f.write(f"'\n=== {test_name} {phase.upper()} INFO ===\n")
f.write(tr[phase].longreprtext)
Expand Down

0 comments on commit 8a7b37e

Please sign in to comment.