Skip to content

Commit

Permalink
python buildPythonPackage: check and run correct test command
Browse files Browse the repository at this point in the history
The default command for running tests is `python setup.py test`.  Many
packages use a test runner that needs to be invoked, e.g. `nosetests` or
`py.test`. It would be nice if `buildPythonPackage` automatically
determines which command to run.

We can check in the `buildInputs` whether `nose` or `pytest` is
included, and if so, do either 1) or 2)

1. Run the appropriate command, `nosetests` or `py.test`.
2. Apply a patch to enable `python setup.py test`. For
[py.test](http://pytest.org/latest/goodpractises.html#integrating-with-
setuptools-python-setup-py-test-pytest-runner) and
[nose](http://nose.readthedocs.org/en/latest/api/commands.html)

Option 2) could get complicated/messy and therefore I'm in favor of
option 1).

This commit implements option 1.

---
Reference to NixOS#1819
  • Loading branch information
FRidh committed Dec 14, 2015
1 parent c29702d commit c5e24bd
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions pkgs/development/python-modules/generic/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
(http://pypi.python.org/pypi/setuptools/), which represents a large
number of Python packages nowadays. */

{ python, setuptools, unzip, wrapPython, lib, bootstrapped-pip }:
{ python, setuptools, unzip, which, wrapPython, lib, bootstrapped-pip }:

{ name

Expand Down Expand Up @@ -59,7 +59,7 @@ in
python.stdenv.mkDerivation (builtins.removeAttrs attrs ["disabled" "doCheck"] // {
name = namePrefix + name;

buildInputs = [ wrapPython bootstrapped-pip ] ++ buildInputs ++ pythonPath
buildInputs = [ which wrapPython bootstrapped-pip ] ++ buildInputs ++ pythonPath
++ (lib.optional (lib.hasSuffix "zip" attrs.src.name or "") unzip);

# propagate python/setuptools to active setup-hook in nix-shell
Expand Down Expand Up @@ -103,9 +103,18 @@ python.stdenv.mkDerivation (builtins.removeAttrs attrs ["disabled" "doCheck"] //
# a common idiom in Python
doInstallCheck = doInstallCheck;

# We check which test runner is available and run that one
installCheckPhase = attrs.checkPhase or ''
runHook preCheck
${python.interpreter} nix_run_setup.py test
if which py.test; then
py.test
elif which nosetests; then
nosetests
else
${python.interpreter} nix_run_setup.py test
fi
runHook postCheck
'';

Expand Down

0 comments on commit c5e24bd

Please sign in to comment.