pythonPackages.unittestCheckHook: init

This commit is contained in:
Winter 2022-08-06 12:31:53 -04:00
parent a5a853e446
commit e8fbb38a51
4 changed files with 49 additions and 0 deletions

View File

@ -734,6 +734,16 @@ work in any of the formats supported by `buildPythonPackage` currently,
with the exception of `other` (see `format` in
[`buildPythonPackage` parameters](#buildpythonpackage-parameters) for more details).
### Using unittestCheckHook {#using-unittestcheckhook}
`unittestCheckHook` is a hook which will substitute the setuptools `test` command for a `checkPhase` which runs `python -m unittest discover`:
```
checkInputs = [ unittestCheckHook ];
unittestFlags = [ "-s" "tests" "-v" ];
```
### Develop local package {#develop-local-package}
As a Python developer you're likely aware of [development mode](http://setuptools.readthedocs.io/en/latest/setuptools.html#development-mode)
@ -1270,6 +1280,7 @@ are used in `buildPythonPackage`.
with the `pipInstallHook`.
- `pythonRelaxDepsHook` will relax Python dependencies restrictions for the package.
See [example usage](#using-pythonrelaxdepshook).
- `unittestCheckHook` will run tests with `python -m unittest discover`. See [example usage](#using-unittestcheckhook).
### Development mode {#development-mode}

View File

@ -164,6 +164,14 @@ in rec {
};
} ./setuptools-check-hook.sh) {};
unittestCheckHook = callPackage ({ }:
makeSetupHook {
name = "unittest-check-hook";
substitutions = {
inherit pythonCheckInterpreter;
};
} ./unittest-check-hook.sh) {};
venvShellHook = disabledIf (!isPy3k) (callPackage ({ }:
makeSetupHook {
name = "venv-shell-hook";

View File

@ -0,0 +1,29 @@
# Setup hook for unittest.
echo "Sourcing unittest-check-hook"
unittestCheckPhase() {
echo "Executing unittestCheckPhase"
runHook preCheck
eval "@pythonCheckInterpreter@ -m unittest discover $unittestFlagsArray"
runHook postCheck
echo "Finished executing unittestCheckPhase"
}
if [ -z "${dontUseUnittestCheck-}" ] && [ -z "${installCheckPhase-}" ]; then
echo "Using unittestCheckPhase"
preDistPhases+=" unittestCheckPhase"
# It's almost always the case that setuptoolsCheckPhase should not be ran
# when the unittestCheckHook is being ran
if [ -z "${useSetuptoolsCheck-}" ]; then
dontUseSetuptoolsCheck=1
# Remove command if already injected into preDistPhases
if [[ "$preDistPhases" =~ "setuptoolsCheckPhase" ]]; then
echo "Removing setuptoolsCheckPhase"
preDistPhases=${preDistPhases/setuptoolsCheckPhase/}
fi
fi
fi

View File

@ -125,6 +125,7 @@ in {
pythonRemoveTestsDirHook
setuptoolsBuildHook
setuptoolsCheckHook
unittestCheckHook
venvShellHook
wheelUnpackHook;