The check took ../tests/unit alone, so the broker's, the pointer driver's and the sessions suites were collected by no check at all -- 432 of 551 tests ran only when someone happened to enter the dev shell. It now takes ../tests, which surfaced two real defects in the harness rather than in the code: - tests/sessions/integration/test_lifecycle.py locates the repository by looking upward for a pyproject.toml, which a build has no reason to contain; it raised at import and took the whole run down as a collection error. The check now copies the marker in, which is what the test documents it needs. - That file also REPLACED PYTHONPATH for the daemon it spawns instead of prepending to it. In a checkout src/ is the package, so it worked; under a build it discarded the package under test, and 'python -m hhstreamd' died at startup with an ImportError -- reported as a daemon failure on every test in the file. Prepending is the fix, and the right behaviour anywhere. pywayland joins the test environment because the pointer driver imports it. unit: 551 collected, 550 passed, 1 skipped (a deliberate skip).
92 lines
3.0 KiB
Nix
92 lines
3.0 KiB
Nix
# checks.<system>.unit -- the Python unit suite from tests/, run against the
|
|
# package built by nix/package.nix, inside the build sandbox.
|
|
#
|
|
# The whole tree, not one directory: it used to take tests/unit alone, which
|
|
# meant the broker's and the pointer driver's suites (and the sessions one) were
|
|
# never collected by any check -- a gate that could not see 432 of 551 tests.
|
|
#
|
|
# pywayland is in the test environment because the pointer driver imports it;
|
|
# without it those tests fail as an import error rather than as the thing they
|
|
# test.
|
|
#
|
|
# nix/package.nix sets doCheck = false deliberately, so this is the only place
|
|
# the suite runs in a build.
|
|
{
|
|
lib,
|
|
runCommand,
|
|
python3,
|
|
hhstream,
|
|
}:
|
|
let
|
|
pytestEnv = python3.withPackages (ps: [ ps.pytest ps.pywayland ]);
|
|
|
|
# Only the suite itself, so an editor's droppings or a local .pytest_cache
|
|
# cannot change the derivation's hash.
|
|
testSrc = lib.cleanSourceWith {
|
|
name = "hhstream-tests";
|
|
src = ../tests;
|
|
filter =
|
|
path: type:
|
|
let
|
|
base = baseNameOf (toString path);
|
|
in
|
|
!(type == "directory" && (base == "__pycache__" || base == ".pytest_cache"))
|
|
&& !lib.hasSuffix ".pyc" base;
|
|
};
|
|
in
|
|
runCommand "hhstream-unit"
|
|
{
|
|
nativeBuildInputs = [ pytestEnv ];
|
|
passthru.testSrc = testSrc;
|
|
meta.description = "hhstream unit tests (pytest)";
|
|
} ''
|
|
cp -r ${testSrc} suite
|
|
chmod -R u+w suite
|
|
|
|
# `tests/sessions/integration/test_lifecycle.py` locates the repository by
|
|
# looking upward for a `pyproject.toml` (it needs the root for `src/` on
|
|
# PYTHONPATH and as a cwd for the subprocesses it spawns). In a build there is
|
|
# no repository above the copied suite, so it raises at import time and takes
|
|
# the whole run down as a collection error. Giving it the marker it documents
|
|
# is the fix; the test itself is hermetic -- no compositor, no network.
|
|
cp ${../pyproject.toml} suite/pyproject.toml
|
|
|
|
# The package is an application, so its library is not on the default path:
|
|
# point PYTHONPATH at what nix/package.nix installed. Importing it here rather
|
|
# than letting pytest do it makes a packaging problem distinguishable from a
|
|
# test failure.
|
|
export PYTHONPATH=${hhstream}/${python3.sitePackages}
|
|
export PYTHONDONTWRITEBYTECODE=1
|
|
export HOME=$PWD
|
|
python3 -c 'import hhstream; print("testing hhstream", hhstream.__version__, "from", hhstream.__file__)'
|
|
python3 -c 'import hhstreamd.ipc, hhstream_pointer; print("broker ipc client + pointer driver import")'
|
|
|
|
set +e
|
|
pytest suite \
|
|
--color=no -rf -q \
|
|
--junit-xml=report.xml \
|
|
-p no:cacheprovider \
|
|
--strict-markers \
|
|
--strict-config
|
|
pytest_rc=$?
|
|
set -e
|
|
|
|
echo
|
|
set +e
|
|
python3 ${./lib/check_report.py} report.xml
|
|
report_rc=$?
|
|
set -e
|
|
|
|
if [ "$report_rc" -eq 1 ]; then
|
|
echo "unit check: the suite is empty or its report is unusable -- failing." >&2
|
|
exit 1
|
|
fi
|
|
if [ "$report_rc" -ne 0 ] || [ "$pytest_rc" -ne 0 ]; then
|
|
echo "unit check: the suite ran but did not pass (pytest exit $pytest_rc)." >&2
|
|
exit 1
|
|
fi
|
|
|
|
mkdir -p $out
|
|
cp report.xml $out/junit.xml
|
|
''
|