(Warning: question follows after long introduction)
When creating new Python package definitions or debugging or upgrading existing ones, it often happens that the tests fail. It is then useful to debug these somehow.
To do this, I have found it useful to edit the derivation (temporarily – until the problems are resolved) in the following way:
- turn off the checkPhase (given that the tests fail, this is required to install anything at all)
- figure out what the command is to run the tests
- figure out the location of the sources in the nix store. (this can be done by reading the build’s output)
- promote any (test-related) nativeBuildInputs or checkInputs to propagatedBuildInputs (we need them to be able to rerun the tests manually later on)
- Create a shell.nix like so:
with import <nixpkgs> {};
(pkgs.python3.withPackages (ps: with ps; [
the-package-we-care-about
])).env
- run nix-shell.
- from inside the shell, debug the tests, by running the tests with an interactive debugger on failure. E.g. (for pytest)
pytest --pdb
Optionally:
- If the interactive debugger by itself is not sufficient, unpacking the full source from the nix store to an editable location, navigating to that location and running the tests from there may be useful.
And now for the question:
In the above, a number of steps involve the temporary manual editing of the expression we’re trying to get to run, only to revert such manual changes later. It would be nice if there was a utility, that could be applied to a package definition, and which would automatically do the following:
- turn off checkPhase
- make the actually used checkPhase easily printable, e.g. by introducing a command of a known name into the environment which prints it to screen)
- make source location easily printable (in a similar way)
- promote all
nativeBuildInputs
andcheckInputs
topropagatedBuildInputs
- optionally: override
src
to point to a local checkout.
with import <nixpkgs> {};
(pkgs.python3.withPackages (ps: with ps; [
debug-python-tests the-package-we-care-about
])).env
Unfortuntately, I’m not fluent enough in nix and the mechanisms for attr-overriding to come up with the definition for debug-python-tests. Any pointers are much appreciated!