python39Packages.pytest-xdist: add hook to add flags

many of our packages have pytest-xdist in their inputs however
oftentimes the required flags aren't added to pytest flags
since we dont use tox and other frameworks

some examples of improvements
(my pc has ryzen 9 5900x)
hypothesis 11m:15s on hydra -> <1m on my pc
hypothesmith 8m on my pc -> <1m on my pc

the whole graph from pytest-xdist (tested by adding postPatch with true to xdist)
time nix build ".#python3Packages.hypothesmith"
19m:57s -> 9m:13s
This commit is contained in:
Artturin 2022-03-31 00:40:17 +03:00 committed by Martin Weinelt
parent 3b3bf22264
commit 50402f8839
2 changed files with 15 additions and 0 deletions

View File

@ -29,6 +29,12 @@ buildPythonPackage rec {
checkInputs = [ pytestCheckHook filelock pexpect ];
propagatedBuildInputs = [ execnet pytest-forked psutil ];
pytestFlagsArray = [
# pytest can already use xdist at this point
"--numprocesses=$NIX_BUILD_CORES"
"--forked"
];
# access file system
disabledTests = [
"test_distribution_rsyncdirs_example"
@ -41,6 +47,8 @@ buildPythonPackage rec {
"test_internal_errors_propagate_to_controller"
];
setupHook = ./setup-hook.sh;
meta = with lib; {
description = "Pytest xdist plugin for distributed testing and loop-on-failing modes";
homepage = "https://github.com/pytest-dev/pytest-xdist";

View File

@ -0,0 +1,7 @@
pytestXdistHook() {
pytestFlagsArray+=("--numprocesses=$NIX_BUILD_CORES" "--forked" )
}
if [ -z "${dontUsePytestXdist-}" ] && [ -z "${dontUsePytestCheck-}" ]; then
addEnvHooks "$hostOffset" pytestXdistHook
fi