Skip to content
This repository was archived by the owner on Aug 13, 2025. It is now read-only.

Commit f556bbb

Browse files
committed
Ensure system test programs and deps are compiled
Some system tests require extra programs and/or dependencies to be compiled first. This is done via `make check` with the automake framework when using check_* variables such as check_PROGRAMS. To avoid running any tests via the automake framework, set the TESTS env variable to empty string and utilize `make -e check` to override default Makefile variables with environment ones. This ensures automake will only compile the needed dependencies without running any tests. Additional consideration needs to be taken for xdist. The compilation command should be called just once before any tests are executed. To achieve that, use the pytest_configure() hook and check that the PYTEST_XDIST_WORKER env variable isn't set -- if it is, it indicates we're in the spawned xdist worker and the compilation was already done by the main pytest process that spawned the workers. This is mostly done to have on-par functionality with legacy test framework. In the future, we should get rid of the need to run "empty" make -e check and perhaps compile test-stuff by default.
1 parent e1935ec commit f556bbb

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

bin/tests/system/conftest.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def control_port():
5656

5757
# ----------------------- Globals definition -----------------------------
5858

59+
XDIST_WORKER = os.environ.get("PYTEST_XDIST_WORKER", "")
5960
FILE_DIR = os.path.abspath(Path(__file__).parent)
6061
ENV_RE = re.compile("([^=]+)=(.*)")
6162

@@ -90,3 +91,31 @@ def get_env(cmd):
9091
CONF_ENV = get_env(". ./conf.sh && env")
9192
os.environ.update(CONF_ENV)
9293
logging.debug("conf.sh env: %s", CONF_ENV)
94+
95+
# --------------------------- pytest hooks -------------------------------
96+
97+
def pytest_configure():
98+
# Ensure this hook only runs on the main pytest instance if xdist is
99+
# used to spawn other workers.
100+
if not XDIST_WORKER:
101+
logging.debug("compiling required files")
102+
env = os.environ.copy()
103+
env["TESTS"] = "" # disable automake test framework - compile-only
104+
try:
105+
# FUTURE: Remove the need to run this compilation command
106+
# before executing tests. Currently it's only here to have
107+
# on-par functionality with the legacy test framework.
108+
proc = subprocess.run(
109+
"make -e check",
110+
shell=True,
111+
check=True,
112+
cwd=FILE_DIR,
113+
stdout=subprocess.PIPE,
114+
stderr=subprocess.STDOUT,
115+
env=env,
116+
)
117+
except subprocess.CalledProcessError as exc:
118+
logging.debug(exc.stdout)
119+
logging.error("failed to compile test files: %s", exc)
120+
raise exc
121+
logging.debug(proc.stdout)

0 commit comments

Comments
 (0)