From 0ee6de86afb6e1d044eaa1d051d3327f4b05562e Mon Sep 17 00:00:00 2001 From: DavHau Date: Tue, 19 Sep 2023 16:46:38 +0200 Subject: [PATCH] checks: run impure pytest tests in CI pipeline --- checks/impure/flake-module.nix | 26 +++++++++++++++++++++++++- pkgs/clan-cli/default.nix | 1 + pkgs/clan-cli/tests/root.py | 8 +++++++- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/checks/impure/flake-module.nix b/checks/impure/flake-module.nix index 4d571c4d..de96bc4b 100644 --- a/checks/impure/flake-module.nix +++ b/checks/impure/flake-module.nix @@ -2,6 +2,30 @@ perSystem = { pkgs, lib, self', ... }: let impureChecks = { + clan-pytest-impure = pkgs.writeShellScriptBin "clan-pytest-impure" '' + #!${pkgs.bash}/bin/bash + set -euo pipefail + + export TMPDIR=$(${pkgs.coreutils}/bin/mktemp -d) + trap "${pkgs.coreutils}/bin/chmod -R +w '$TMPDIR'; ${pkgs.coreutils}/bin/rm -rf '$TMPDIR'" EXIT + + export PATH="${lib.makeBinPath [ + pkgs.coreutils + pkgs.gitMinimal + pkgs.nix + self'.packages.clan-cli.checkPython + ]}" + + export CLAN_CORE=$TMPDIR/CLAN_CORE + cp -r ${self} $CLAN_CORE + chmod +w -R $CLAN_CORE + + cp -r ${self'.packages.clan-cli.src} $TMPDIR/src + chmod +w -R $TMPDIR/src + cd $TMPDIR/src + + python -m pytest -m "impure" -s ./tests --workers "" "$@" + ''; check-clan-template = pkgs.writeShellScriptBin "check-clan-template" '' #!${pkgs.bash}/bin/bash set -euo pipefail @@ -55,7 +79,7 @@ set -euo pipefail ${lib.concatMapStringsSep "\n" (name: '' echo -e "\n\nrunning check ${name}\n" - ${impureChecks.${name}}/bin/* + ${impureChecks.${name}}/bin/* "$@" '') (lib.attrNames impureChecks)} ''; }; diff --git a/pkgs/clan-cli/default.nix b/pkgs/clan-cli/default.nix index f41152ff..7f601c26 100644 --- a/pkgs/clan-cli/default.nix +++ b/pkgs/clan-cli/default.nix @@ -104,6 +104,7 @@ python3.pkgs.buildPythonPackage { touch $out ''; passthru.nixpkgs = nixpkgs; + passthru.checkPython = checkPython; passthru.devDependencies = [ setuptools diff --git a/pkgs/clan-cli/tests/root.py b/pkgs/clan-cli/tests/root.py index 0105e82a..d1c70220 100644 --- a/pkgs/clan-cli/tests/root.py +++ b/pkgs/clan-cli/tests/root.py @@ -1,10 +1,16 @@ +import os from pathlib import Path import pytest TEST_ROOT = Path(__file__).parent.resolve() PROJECT_ROOT = TEST_ROOT.parent -CLAN_CORE = PROJECT_ROOT.parent.parent + +CLAN_CORE_ = os.environ.get("CLAN_CORE") +if CLAN_CORE_: + CLAN_CORE = Path(CLAN_CORE_) +else: + CLAN_CORE = PROJECT_ROOT.parent.parent @pytest.fixture(scope="session")