diff --git a/checks/unit.nix b/checks/unit.nix index 389f3fb..de0ac15 100644 --- a/checks/unit.nix +++ b/checks/unit.nix @@ -1,6 +1,14 @@ -# checks..unit -- the Python unit suite from tests/unit/, run against the +# checks..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. { @@ -10,13 +18,13 @@ hhstream, }: let - pytestEnv = python3.withPackages (ps: [ ps.pytest ]); + 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-unit-tests"; - src = ../tests/unit; + name = "hhstream-tests"; + src = ../tests; filter = path: type: let @@ -35,6 +43,14 @@ runCommand "hhstream-unit" 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 @@ -43,6 +59,7 @@ runCommand "hhstream-unit" 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 \ diff --git a/tests/sessions/integration/test_lifecycle.py b/tests/sessions/integration/test_lifecycle.py index 6c51569..952b522 100644 --- a/tests/sessions/integration/test_lifecycle.py +++ b/tests/sessions/integration/test_lifecycle.py @@ -52,7 +52,17 @@ def _repo_root() -> Path: REPO_ROOT = _repo_root() #: The package lives under `src/` here. Keep the root too, so a flat checkout works. -IMPORT_PATH = os.pathsep.join([str(REPO_ROOT / "src"), str(REPO_ROOT)]) +#: +#: These are PREPENDED to whatever PYTHONPATH we inherited rather than replacing +#: it. Clobbering it works in a checkout, where `src/` is the package, but under +#: a build (checks/unit.nix) the package under test is what the inherited path +#: points at -- so replacing it made `python -m hhstreamd` die at startup with an +#: ImportError, and every test in this file error out in its setup, which reads +#: as a daemon bug rather than a harness one. +_CHECKOUT_PATH = os.pathsep.join([str(REPO_ROOT / "src"), str(REPO_ROOT)]) +IMPORT_PATH = os.pathsep.join( + p for p in (_CHECKOUT_PATH, os.environ.get("PYTHONPATH", "")) if p +) # The brief's dummy app, verbatim. SLEEP_600 = "import time; time.sleep(600)"