mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-05-05 22:08:27 +00:00
system tests: improve log output
This commit is contained in:
@@ -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 echo deb http://deb.debian.org/debian bookworm-backports main > /etc/apt/sources.list.d/backports.list
|
||||||
RUN apt-get update && \
|
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/*
|
apt-get clean && rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
RUN useradd -m --shell /bin/sh --home-dir /var/lib/aptly aptly
|
RUN useradd -m --shell /bin/sh --home-dir /var/lib/aptly aptly
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import urllib.error
|
|||||||
import urllib.parse
|
import urllib.parse
|
||||||
import urllib.request
|
import urllib.request
|
||||||
import zlib
|
import zlib
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
|
||||||
@@ -246,7 +247,7 @@ class BaseTest(object):
|
|||||||
if hasattr(self, "fixtureCmds"):
|
if hasattr(self, "fixtureCmds"):
|
||||||
for cmd in self.fixtureCmds:
|
for cmd in self.fixtureCmds:
|
||||||
output = self.run_cmd(cmd)
|
output = self.run_cmd(cmd)
|
||||||
print("\n")
|
print("fixture Output:\n")
|
||||||
for line in output.decode("utf-8").split("\n"):
|
for line in output.decode("utf-8").split("\n"):
|
||||||
print(f" {line}")
|
print(f" {line}")
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
rm -rf /app/tmp
|
rm -rf /app/tmp
|
||||||
rm -rf /tmp/aptly*
|
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
|
chown -R `stat -c %u /app` /var/lib/aptly
|
||||||
|
|
||||||
# use same /home/runner dir as in github workflow
|
# use same /home/runner dir as in github workflow
|
||||||
|
|||||||
@@ -43,6 +43,23 @@ def walk_modules(package):
|
|||||||
yield importlib.import_module(package + "." + name)
|
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):
|
def run(include_long_tests=False, capture_results=False, tests=None, filters=None, coverage_dir=None):
|
||||||
"""
|
"""
|
||||||
Run system test.
|
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")
|
coverage_dir = mkdtemp(suffix="aptly-coverage")
|
||||||
|
|
||||||
for test in tests:
|
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):
|
for name in sorted(dir(testModule), key=natural_key):
|
||||||
|
testout.truncate()
|
||||||
o = getattr(testModule, name)
|
o = getattr(testModule, name)
|
||||||
|
|
||||||
if not (inspect.isclass(o) and issubclass(o, BaseTest) and o is not BaseTest and
|
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:
|
if not matches:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
sys.stdout.write(colored("%s:%s... ", color="yellow", attrs=["bold"]) % (test, o.__name__))
|
orig_stdout.write(colored("%s: %s ... ", color="yellow", attrs=["bold"]) % (test, o.__name__))
|
||||||
sys.stdout.flush()
|
orig_stdout.flush()
|
||||||
|
|
||||||
t = o()
|
t = o()
|
||||||
|
|
||||||
if t.longTest and not include_long_tests or not t.fixture_available() or t.skipTest:
|
if t.longTest and not include_long_tests or not t.fixture_available() or t.skipTest:
|
||||||
numSkipped += 1
|
numSkipped += 1
|
||||||
msg = 'SKIP'
|
msg = 'SKIP'
|
||||||
if t.skipTest and t.skipTest is not True:
|
if t.skipTest and t.skipTest is not True:
|
||||||
# If we have a reason to skip, print it
|
# If we have a reason to skip, print it
|
||||||
msg += ': ' + t.skipTest
|
msg += ': ' + t.skipTest
|
||||||
sys.stdout.write(colored(msg + "\n", color="yellow"))
|
orig_stdout.write(colored(msg + "\n", color="yellow"))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
numTests += 1
|
numTests += 1
|
||||||
@@ -104,13 +136,18 @@ def run(include_long_tests=False, capture_results=False, tests=None, filters=Non
|
|||||||
numFailed += 1
|
numFailed += 1
|
||||||
typ, val, tb = sys.exc_info()
|
typ, val, tb = sys.exc_info()
|
||||||
fails.append((test, t, typ, val, tb, testModule))
|
fails.append((test, t, typ, val, tb, testModule))
|
||||||
traceback.print_exception(typ, val, tb)
|
orig_stdout.write(colored("\b\b\b\bFAIL\n", color="red", attrs=["bold"]))
|
||||||
sys.stdout.write(colored("FAIL\n", color="red", attrs=["bold"]))
|
|
||||||
|
orig_stdout.write(testout.get_output())
|
||||||
|
traceback.print_exception(typ, val, tb, file=orig_stdout)
|
||||||
else:
|
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()
|
t.shutdown()
|
||||||
|
|
||||||
|
sys.stdout = orig_stdout
|
||||||
|
sys.stderr = orig_stderr
|
||||||
|
|
||||||
if lastBase is not None:
|
if lastBase is not None:
|
||||||
lastBase.shutdown_class()
|
lastBase.shutdown_class()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user