system tests: improve log output

This commit is contained in:
André Roth
2024-06-08 15:37:18 +02:00
parent 34c1c1f83a
commit d8cfafccc9
4 changed files with 48 additions and 10 deletions

View File

@@ -4,7 +4,7 @@ RUN apt-get update -y && apt-get install -y --no-install-recommends curl gnupg &
RUN echo deb http://deb.debian.org/debian bookworm-backports main > /etc/apt/sources.list.d/backports.list
RUN apt-get update && \
apt-get install -y --no-install-recommends apg bzip2 xz-utils ca-certificates golang/bookworm-backports golang-go/bookworm-backports golang-doc/bookworm-backports golang-src/bookworm-backports make git python3 python3-requests-unixsocket python3-termcolor && \
apt-get install -y --no-install-recommends apg bzip2 xz-utils ca-certificates golang/bookworm-backports golang-go/bookworm-backports golang-doc/bookworm-backports golang-src/bookworm-backports make git python3 python3-requests-unixsocket python3-termcolor python3-swiftclient python3-boto && \
apt-get clean && rm -rf /var/lib/apt/lists/*
RUN useradd -m --shell /bin/sh --home-dir /var/lib/aptly aptly

View File

@@ -20,6 +20,7 @@ import urllib.error
import urllib.parse
import urllib.request
import zlib
from pathlib import Path
from uuid import uuid4
@@ -246,7 +247,7 @@ class BaseTest(object):
if hasattr(self, "fixtureCmds"):
for cmd in self.fixtureCmds:
output = self.run_cmd(cmd)
print("\n")
print("fixture Output:\n")
for line in output.decode("utf-8").split("\n"):
print(f" {line}")

View File

@@ -4,7 +4,7 @@
rm -rf /app/tmp
rm -rf /tmp/aptly*
usermod -u `stat -c %u /app` aptly
usermod -u `stat -c %u /app` aptly >/dev/null
chown -R `stat -c %u /app` /var/lib/aptly
# use same /home/runner dir as in github workflow

View File

@@ -43,6 +43,23 @@ def walk_modules(package):
yield importlib.import_module(package + "." + name)
class TestStdout:
def __init__(self):
self.output = []
def write(self, text):
self.output.append(text)
def flush(self):
pass
def get_output(self):
return ''.join(self.output)
def truncate(self):
self.output = []
def run(include_long_tests=False, capture_results=False, tests=None, filters=None, coverage_dir=None):
"""
Run system test.
@@ -56,8 +73,22 @@ def run(include_long_tests=False, capture_results=False, tests=None, filters=Non
coverage_dir = mkdtemp(suffix="aptly-coverage")
for test in tests:
for testModule in walk_modules(test):
orig_stdout = sys.stdout
orig_stderr = sys.stderr
# importlib.import_module(test)
for name in sorted(glob.glob(test + "/*.py"), key=natural_key):
name = os.path.splitext(os.path.basename(name))[0]
if name == "__init__":
continue
testout = TestStdout()
sys.stdout = testout
sys.stderr = testout
testModule = importlib.import_module(test + "." + name)
for name in sorted(dir(testModule), key=natural_key):
testout.truncate()
o = getattr(testModule, name)
if not (inspect.isclass(o) and issubclass(o, BaseTest) and o is not BaseTest and
@@ -81,17 +112,18 @@ def run(include_long_tests=False, capture_results=False, tests=None, filters=Non
if not matches:
continue
sys.stdout.write(colored("%s:%s... ", color="yellow", attrs=["bold"]) % (test, o.__name__))
sys.stdout.flush()
orig_stdout.write(colored("%s: %s ... ", color="yellow", attrs=["bold"]) % (test, o.__name__))
orig_stdout.flush()
t = o()
if t.longTest and not include_long_tests or not t.fixture_available() or t.skipTest:
numSkipped += 1
msg = 'SKIP'
if t.skipTest and t.skipTest is not True:
# If we have a reason to skip, print it
msg += ': ' + t.skipTest
sys.stdout.write(colored(msg + "\n", color="yellow"))
orig_stdout.write(colored(msg + "\n", color="yellow"))
continue
numTests += 1
@@ -104,13 +136,18 @@ def run(include_long_tests=False, capture_results=False, tests=None, filters=Non
numFailed += 1
typ, val, tb = sys.exc_info()
fails.append((test, t, typ, val, tb, testModule))
traceback.print_exception(typ, val, tb)
sys.stdout.write(colored("FAIL\n", color="red", attrs=["bold"]))
orig_stdout.write(colored("\b\b\b\bFAIL\n", color="red", attrs=["bold"]))
orig_stdout.write(testout.get_output())
traceback.print_exception(typ, val, tb, file=orig_stdout)
else:
sys.stdout.write(colored("OK\n", color="green", attrs=["bold"]))
orig_stdout.write(colored("\b\b\b\bOK \n", color="green", attrs=["bold"]))
t.shutdown()
sys.stdout = orig_stdout
sys.stderr = orig_stderr
if lastBase is not None:
lastBase.shutdown_class()