py-test.mk: Generate conftest.py
All checks were successful
CI / Packaging - Kali Linux (pull_request) Successful in 4m21s
CI / Packaging - OpenSUSE Tumbleweed (pull_request) Successful in 4m40s
CI / Packaging test (pull_request) Successful in 0s
CI / Packaging - Kali Linux (push) Successful in 4m6s
CI / Packaging - OpenSUSE Tumbleweed (push) Successful in 4m12s
CI / Packaging test (push) Successful in 0s

Generate a standard conftest.py, mostly for customizing pytest's bombastic test header, which otherwise lets the more informative make output look too pale in comparison.

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2026-07-02 17:20:08 +02:00
commit 0c92d942ec
Signed by: Jan Lindemann
GPG key ID: 3750640C9E25DD61
2 changed files with 51 additions and 1 deletions

View file

@ -1,6 +1,23 @@
PYTHON_RUNNER ?= pytest -v
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

@ -32,6 +32,39 @@ module_path()
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()
{
__add_seen() {