make: Improve Python testing support #45

Merged
Jan Lindemann merged 3 commits from jan/feature/20260702-improve-python-testing-support into master 2026-07-02 20:01:44 +02:00 AGit
20 changed files with 80 additions and 17 deletions

View file

@ -5,7 +5,8 @@
include $(JWBDIR)/make/defs.mk include $(JWBDIR)/make/defs.mk
all:
all install: all install:
clean distclean: clean distclean:
$(RM) -rf $(filter-out $(LOCAL_MKFILES) CVS debug release,$(wildcard *)) $(RM) -rf $(filter-out $(LOCAL_MKFILES) CVS debug release,$(wildcard *))
test: test: all

View file

@ -4,6 +4,7 @@ all: do.all
install: do.install install: do.install
clean: do.clean clean: do.clean
distclean: do.distclean distclean: do.distclean
test:
include $(JWBDIR)/make/defs.mk include $(JWBDIR)/make/defs.mk
include $(JWBDIR)/make/defs-dirs.mk include $(JWBDIR)/make/defs-dirs.mk

View file

@ -6,7 +6,7 @@ all:
clean: clean.conf clean: clean.conf
install: install_CFG install_files_SYSCFG install_files_LOGROT install_files_CRONTAB install_files_RSYSLOG \ install: install_CFG install_files_SYSCFG install_files_LOGROT install_files_CRONTAB install_files_RSYSLOG \
install_files_APACHE_CONF install_files_SYSTEMD install_files_INIT install_files_TMPFILES $(CONF_D) install_files_APACHE_CONF install_files_SYSTEMD install_files_INIT install_files_TMPFILES $(CONF_D)
test: test: all
clean.conf: clean.conf:
$(RM) -rf *~ .*.swp *.done $(RM) -rf *~ .*.swp *.done

View file

@ -8,6 +8,6 @@ install:
clean: clean:
distclean: distclean:
check: check:
test: test: all
get-%: get-%:
pkg-%: pkg-%:

View file

@ -9,7 +9,7 @@ include $(JWBDIR)/make/dev-utils.mk
all: $(EXE) $(BUILD_EXE_BIN) $(STRIP_DONE) all: $(EXE) $(BUILD_EXE_BIN) $(STRIP_DONE)
install: $(INSTALLED_EXE) $(INSTALLED_EXE_BIN) install: $(INSTALLED_EXE) $(INSTALLED_EXE_BIN)
run test: all.dirs $(EXE) $(EXE_BIN) run test: all all.dirs $(EXE) $(EXE_BIN)
strace: $(EXE) $(EXE_BIN) strace: $(EXE) $(EXE_BIN)
clean: execlean localclean profclean clean: execlean localclean profclean

View file

@ -22,7 +22,7 @@ clean: clean-mo
$(RM) -rf *~ .*.swp $(RM) -rf *~ .*.swp
install: install_MO install: install_MO
distclean: clean distclean: clean
test: test: all
extract: $(GETTEXT_POT) extract: $(GETTEXT_POT)
clean-mo: clean-mo:

View file

@ -30,7 +30,7 @@ include $(JWBDIR)/make/dev-utils.mk
all: $(LESS_GENERATED_CSS) lint all: $(LESS_GENERATED_CSS) lint
install: install_HTML install: install_HTML
clean: textclean localclean doneclean clean.lesscpy clean: textclean localclean doneclean clean.lesscpy
test: test: all
%.css: %.less %.css: %.less
$(LESS_CPY) $< > $@.tmp $(LESS_CPY) $< > $@.tmp

View file

@ -42,7 +42,7 @@ all: build_PKG_CONFIG
endif endif
install: $(DEVEL_TARGETS) install: $(DEVEL_TARGETS)
clean: textclean localclean doneclean clean.pkg-config clean: textclean localclean doneclean clean.pkg-config
test: test: all
$(INSTALL_PCKG_DEPS_DIR)/$(PROJECT).mk: pckg-deps.mk $(INSTALL_PCKG_DEPS_DIR)/$(PROJECT).mk: pckg-deps.mk
mkdir -p $(dir $@) mkdir -p $(dir $@)

View file

@ -18,7 +18,7 @@ include $(JWBDIR)/make/rules.mk
all: $(PROFILE) all: $(PROFILE)
install: install_files_PROFILE install: install_files_PROFILE
clean: allclean localclean doneclean textclean clean.profile clean: allclean localclean doneclean textclean clean.profile
test: test: all
path-%.sh: path-%.sh:
@echo "export PATH=\$$PATH:$(INSTALL_EXEDIR)" > $@.tmp @echo "export PATH=\$$PATH:$(INSTALL_EXEDIR)" > $@.tmp

View file

@ -5,15 +5,16 @@ include $(JWBDIR)/make/py-defs.mk
EXE ?= $(firstword $(wildcard main.py runme.py test.py *.py)) EXE ?= $(firstword $(wildcard main.py runme.py test.py *.py))
EXE_ARGS ?= EXE_ARGS ?=
PYTHON_RUNNER ?= $(PYTHON)
all: all:
install: install:
clean: clean:
distclean: distclean:
test: test: all
run: run:
$(PYTHON) $(EXE) $(EXE_ARGS) $(PYTHON_RUNNER) $(EXE) $(EXE_ARGS)
run.sh: run.sh:
echo -e "#!/bin/bash\n\nexport PYTHONPATH=$(PYTHONPATH)\nset -x\nexec $(PYTHON) $(EXE)" '"$$@"' > $@.tmp echo -e "#!/bin/bash\n\nexport PYTHONPATH=$(PYTHONPATH)\nset -x\nexec $(PYTHON) $(EXE)" '"$$@"' > $@.tmp

23
make/py-test.mk Normal file
View file

@ -0,0 +1,23 @@
PY_CONFTEST ?= conftest.py
PY_UPDATE_PY_CONFTEST ?= true
ifeq ($(PY_UPDATE_PY_CONFTEST),true)
PY_GENERATED += $(PY_CONFTEST)
endif
PY_CONFTEST_CMD ?= /bin/bash $(JWB_SCRIPT_DIR)/python-tools.sh create-conftest-py
PY_TEST_ARGS ?= -v
PYTHON_RUNNER := pytest $(PY_TEST_ARGS)
include $(JWBDIR)/make/py-run.mk
all:
test: run
run: $(PY_GENERATED)
$(PY_CONFTEST):
$(PY_CONFTEST_CMD) > $@.tmp
mv $@.tmp $@
clean: clean.generated
clean.generated:
rm -f $(PY_GENERATED)

View file

@ -66,6 +66,7 @@ all:
install: install:
clean: runclean localclean clean: runclean localclean
distclean: distclean:
test: all
run-deps: all run-deps: all
$(RM) -f core core.* vgcore vgcore.* $(RM) -f core core.* vgcore vgcore.*

View file

@ -1,7 +1,7 @@
all: build_EXE build_CGI all: build_EXE build_CGI
install: install_files_INIT install_EXE install_files_CGI install_files_SYSCFG install: install_files_INIT install_EXE install_files_CGI install_files_SYSCFG
clean:allclean localclean doneclean textclean clean.init clean:allclean localclean doneclean textclean clean.init
test: test: all
ifeq ($(INSTALL_HOME_BIN_WRAPPERS),true) ifeq ($(INSTALL_HOME_BIN_WRAPPERS),true)
install: install-home-bin install: install-home-bin

View file

@ -8,4 +8,4 @@ clean: clean.std-targets
clean.std-targets: clean.std-targets:
$(RM) -rf *~ .*.swp *.done $(RM) -rf *~ .*.swp *.done
distclean: clean distclean: clean
test: test: all

View file

@ -4,6 +4,7 @@ include $(JWBDIR)/make/defs-dirs.mk
all: all:
clean: clean.var clean: clean.var
distclean: clean.var distclean.var distclean: clean.var distclean.var
test:
all install clean distclean test: all install clean distclean test:
ifneq ($(SUBDIRS_TO_ITERATE),) ifneq ($(SUBDIRS_TO_ITERATE),)

View file

@ -13,7 +13,7 @@ clean: execlean localclean profclean testclean
distclean: distclean:
run test: all.dirs $(EXE) $(EXE_BIN) run test: all.dirs $(EXE) $(EXE_BIN)
strace: $(EXE) $(EXE_BIN) strace: $(EXE) $(EXE_BIN)
test: test.done test: all test.done
test.done: test.done:
if ! 2>&1 make run > test.out 2>&1; then \ if ! 2>&1 make run > test.out 2>&1; then \

View file

@ -10,4 +10,4 @@ all:
install: install:
distclean: textclean localclean distclean: textclean localclean
clean: textclean localclean clean: textclean localclean
test: test: all

View file

@ -19,4 +19,4 @@ include $(JWBDIR)/make/rules.mk
all: all:
install: install_TMPL install: install_TMPL
clean: textclean localclean doneclean clean: textclean localclean doneclean
test: test: all

View file

@ -5,6 +5,7 @@
FORCE \ FORCE \
all \ all \
format \ format \
canonicalize-remotes \
check-syntax \ check-syntax \
check-format \ check-format \
check \ check \
@ -42,7 +43,7 @@
pkg-install-release-deps \ pkg-install-release-deps \
pkg-install-testbuild-deps \ pkg-install-testbuild-deps \
recache-vars \ recache-vars \
canonicalize-remotes test
ifeq ($(ORDERED_SUBDIRS),) ifeq ($(ORDERED_SUBDIRS),)
SUBDIRS ?= $(dir $(wildcard $(addsuffix /Makefile,\ SUBDIRS ?= $(dir $(wildcard $(addsuffix /Makefile,\
@ -95,6 +96,7 @@ ifneq ($(SUBDIRS_TO_ITERATE),)
endif endif
all: topdir config all: topdir config
test: all
include $(JWBDIR)/make/dirs.mk include $(JWBDIR)/make/dirs.mk
include $(JWBDIR)/make/pkg-dist.mk include $(JWBDIR)/make/pkg-dist.mk
@ -115,7 +117,7 @@ TD_COPY_FILES ?= $(filter-out Makefile,$(notdir $(wildcard $(TD_CO
TD_COPY_SRC_PATH = $(subst :,$(space),$(JW_PKG_TOPDIR_COPY_PATH)) TD_COPY_SRC_PATH = $(subst :,$(space),$(JW_PKG_TOPDIR_COPY_PATH))
TD_GENERATE_FILES += $(TD_COPY_FILES) TD_GENERATE_FILES += $(TD_COPY_FILES)
all: test: all
format: topdir format: topdir
check-syntax: topdir check-syntax: topdir
check-format: topdir check-format: topdir

View file

@ -32,6 +32,39 @@ module_path()
fi fi
} }
cmd_create_conftest_py()
{
cat <<-'EOT'
import os
import sys
import shutil
def pytest_configure(config):
import _pytest.terminal
import _pytest.timing as timing
# orig = _pytest.terminal.TerminalReporter.pytest_sessionstart
def patched(self, session):
width = shutil.get_terminal_size().columns
d = os.path.basename(os.getcwd())
text = f"Running pytest for {d}"
# Center text within terminal width, matching pytest footer style
padding = width - len(text) - 2
if padding > 0:
left = padding // 2
right = padding - left
banner = "=" * left + f" {text} " + "=" * right
else:
banner = text
print(banner, file = sys.stderr)
self._session = session
self._session_start = timing.Instant()
_pytest.terminal.TerminalReporter.pytest_sessionstart = patched
EOT
}
cmd_create_init() cmd_create_init()
{ {
__add_seen() { __add_seen() {