From 244229a8b6f29264cdd2efbcb64f945980b47871 Mon Sep 17 00:00:00 2001 From: nicoo Date: Thu, 8 Aug 2024 14:28:17 +0000 Subject: [PATCH] python3Packages.bork: add test using `testers.runCommand` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This will serve as a “real-world” example, running tests requiring network. --- pkgs/build-support/testers/test/default.nix | 2 ++ .../python-modules/bork/default.nix | 3 ++ .../development/python-modules/bork/tests.nix | 28 +++++++++++++++++++ 3 files changed, 33 insertions(+) create mode 100644 pkgs/development/python-modules/bork/tests.nix diff --git a/pkgs/build-support/testers/test/default.nix b/pkgs/build-support/testers/test/default.nix index 9ef203b37516..cc46e3cf4b71 100644 --- a/pkgs/build-support/testers/test/default.nix +++ b/pkgs/build-support/testers/test/default.nix @@ -19,6 +19,8 @@ lib.recurseIntoAttrs { shellcheck = pkgs.callPackage ../shellcheck/tests.nix { }; runCommand = lib.recurseIntoAttrs { + bork = pkgs.python3Packages.bork.tests.pytest-network; + dns-resolution = testers.runCommand { name = "runCommand-dns-resolution-test"; nativeBuildInputs = [ pkgs.ldns ]; diff --git a/pkgs/development/python-modules/bork/default.nix b/pkgs/development/python-modules/bork/default.nix index 44a8564558e9..9da54dc1ec69 100644 --- a/pkgs/development/python-modules/bork/default.nix +++ b/pkgs/development/python-modules/bork/default.nix @@ -1,6 +1,7 @@ { lib, buildPythonPackage, + callPackage, fetchFromGitHub, pytestCheckHook, pythonOlder, @@ -61,6 +62,8 @@ buildPythonPackage rec { "test_repo" ]; + passthru.tests = callPackage ./tests.nix { }; + meta = with lib; { description = "Python build and release management tool"; mainProgram = "bork"; diff --git a/pkgs/development/python-modules/bork/tests.nix b/pkgs/development/python-modules/bork/tests.nix new file mode 100644 index 000000000000..7d5c84f2bc35 --- /dev/null +++ b/pkgs/development/python-modules/bork/tests.nix @@ -0,0 +1,28 @@ +{ + testers, + + bork, + cacert, + git, + pytest, +}: +{ + # a.k.a. `tests.testers.runCommand.bork` + pytest-network = testers.runCommand { + name = "bork-pytest-network"; + nativeBuildInputs = [ + bork + cacert + git + pytest + ]; + script = '' + # Copy the source tree over, and make it writeable + cp -r ${bork.src} bork/ + find -type d -exec chmod 0755 '{}' '+' + + pytest -v -m network bork/ + touch $out + ''; + }; +}