Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions doc/languages-frameworks/python.section.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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}

Expand Down
7 changes: 3 additions & 4 deletions pkgs/applications/audio/whipper/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ in python3.pkgs.buildPythonApplication rec {
nativeBuildInputs = with python3.pkgs; [
setuptools-scm
docutils
setuptoolsCheckHook
];

propagatedBuildInputs = with python3.pkgs; [
Expand Down Expand Up @@ -64,14 +65,12 @@ in python3.pkgs.buildPythonApplication rec {
export SETUPTOOLS_SCM_PRETEND_VERSION="${version}"
'';

checkPhase = ''
runHook preCheck
preCheck = ''
# disable tests that require internet access
# https://github.com/JoeLametta/whipper/issues/291
substituteInPlace whipper/test/test_common_accurip.py \
--replace "test_AccurateRipResponse" "dont_test_AccurateRipResponse"
HOME=$TMPDIR ${python3.interpreter} -m unittest discover
runHook postCheck
export HOME=$TMPDIR
'';

passthru.tests.version = testers.testVersion {
Expand Down
6 changes: 2 additions & 4 deletions pkgs/applications/misc/haxor-news/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,9 @@ buildPythonApplication rec {
# will fail without pre-seeded config files
doCheck = false;

checkInputs = [ mock ];
checkInputs = [ unittestCheckHook mock ];

checkPhase = ''
${python.interpreter} -m unittest discover -s tests -v
'';
unittestFlagsArray = [ "-s" "tests" "-v" ];

meta = with lib; {
homepage = "https://github.com/donnemartin/haxor-news";
Expand Down
4 changes: 1 addition & 3 deletions pkgs/applications/misc/pyditz/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ in buildPythonApplication rec {
nativeBuildInputs = [ setuptools-scm ];
propagatedBuildInputs = [ pyyaml six jinja2 cerberus_1_1 ];

checkPhase = ''
${python.interpreter} -m unittest discover
'';
checkInputs = [ unittestCheckHook ];

meta = with lib; {
homepage = "https://pythonhosted.org/pyditz/";
Expand Down
9 changes: 4 additions & 5 deletions pkgs/applications/misc/topydo/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ lib, python3Packages, fetchFromGitHub, glibcLocales }:
{ lib, python3Packages, fetchFromGitHub, glibcLocales, unittestCheckHook }:

with python3Packages;

Expand All @@ -22,16 +22,15 @@ buildPythonApplication rec {
watchdog
];

checkInputs = [ mock freezegun pylint ];
checkInputs = [ unittestCheckHook mock freezegun pylint ];

# Skip test that has been reported multiple times upstream without result:
# bram85/topydo#271, bram85/topydo#274.
checkPhase = ''
preCheck = ''
substituteInPlace test/test_revert_command.py --replace 'test_revert_ls' 'dont_test_revert_ls'
python -m unittest discover
'';

LC_ALL="en_US.UTF-8";
LC_ALL = "en_US.UTF-8";

meta = with lib; {
description = "A cli todo application compatible with the todo.txt format";
Expand Down
8 changes: 8 additions & 0 deletions pkgs/development/interpreters/python/hooks/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
29 changes: 29 additions & 0 deletions pkgs/development/interpreters/python/hooks/unittest-check-hook.sh
Original file line number Diff line number Diff line change
@@ -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
10 changes: 5 additions & 5 deletions pkgs/development/python-modules/aioitertools/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
, typing-extensions

# tests
, python
, unittestCheckHook
}:

buildPythonPackage rec {
Expand All @@ -35,14 +35,14 @@ buildPythonPackage rec {
typing-extensions
];

checkInputs = [
unittestCheckHook
];

pythonImportsCheck = [
"aioitertools"
];

checkPhase = ''
${python.interpreter} -m unittest discover
'';

meta = with lib; {
description = "Implementation of itertools, builtins, and more for AsyncIO and mixed-type iterables";
license = licenses.mit;
Expand Down
10 changes: 6 additions & 4 deletions pkgs/development/python-modules/arxiv2bib/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{ buildPythonPackage, python, lib, fetchFromGitHub
{ buildPythonPackage
, lib
, fetchFromGitHub
, mock
, unittestCheckHook
}:

buildPythonPackage rec {
Expand All @@ -14,9 +17,8 @@ buildPythonPackage rec {
sha256 = "1kp2iyx20lpc9dv4qg5fgwf83a1wx6f7hj1ldqyncg0kn9xcrhbg";
};

checkInputs = [ mock ];

checkPhase = "${python.interpreter} -m unittest discover -s tests";
checkInputs = [ unittestCheckHook mock ];
unittestFlagsArray = [ "-s" "tests" ];

meta = with lib; {
description = "Get a BibTeX entry from an arXiv id number, using the arxiv.org API";
Expand Down
6 changes: 2 additions & 4 deletions pkgs/development/python-modules/awesome-slugify/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ lib, buildPythonPackage, fetchPypi, unidecode, regex, python }:
{ lib, buildPythonPackage, fetchPypi, unidecode, regex, unittestCheckHook }:

buildPythonPackage rec {
pname = "awesome-slugify";
Expand All @@ -20,9 +20,7 @@ buildPythonPackage rec {

propagatedBuildInputs = [ unidecode regex ];

checkPhase = ''
${python.interpreter} -m unittest discover
'';
checkInputs = [ unittestCheckHook ];

meta = with lib; {
homepage = "https://github.com/dimka665/awesome-slugify";
Expand Down
6 changes: 2 additions & 4 deletions pkgs/development/python-modules/backports_abc/default.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{ lib
, buildPythonPackage
, fetchPypi
, python
, unittestCheckHook
}:

buildPythonPackage rec {
Expand All @@ -13,9 +13,7 @@ buildPythonPackage rec {
sha256 = "033be54514a03e255df75c5aee8f9e672f663f93abb723444caec8fe43437bde";
};

checkPhase = ''
${python.interpreter} -m unittest discover
'';
checkInputs = [ unittestCheckHook ];

meta = {
homepage = "https://github.com/cython/backports_abc";
Expand Down
10 changes: 5 additions & 5 deletions pkgs/development/python-modules/backports_tempfile/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{ lib
, python
, unittestCheckHook
, buildPythonPackage
, fetchPypi
, setuptools-scm
Expand All @@ -19,13 +19,13 @@ buildPythonPackage rec {

propagatedBuildInputs = [ backports_weakref ];

checkPhase = ''
${python.interpreter} -m unittest discover -s tests
'';

# requires https://pypi.org/project/backports.test.support
doCheck = false;

checkInputs = [ unittestCheckHook ];

unittestFlagsArray = [ "-s" "tests" ];

meta = {
description = "Backport of new features in Python's tempfile module";
license = lib.licenses.psfl;
Expand Down
8 changes: 4 additions & 4 deletions pkgs/development/python-modules/backports_weakref/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
, fetchPypi
, setuptools-scm
# , backports
, python
, unittestCheckHook
}:

buildPythonPackage rec {
Expand All @@ -20,9 +20,9 @@ buildPythonPackage rec {
# Requires backports package
doCheck = false;

checkPhase = ''
${python.interpreter} -m unittest discover tests
'';
checkInputs = [ unittestCheckHook ];

unittestFlagsArray = [ "tests" ];

meta = with lib; {
description = "Backports of new features in Python’s weakref module";
Expand Down
9 changes: 4 additions & 5 deletions pkgs/development/python-modules/bitstring/default.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{ lib
, buildPythonPackage
, fetchFromGitHub
, python
, unittestCheckHook
}:

buildPythonPackage rec {
Expand All @@ -15,10 +15,9 @@ buildPythonPackage rec {
sha256 = "0y2kcq58psvl038r6dhahhlhp1wjgr5zsms45wyz1naq6ri8x9qa";
};

checkPhase = ''
cd test
${python.interpreter} -m unittest discover
'';
checkInputs = [ unittestCheckHook ];

unittestFlagsArray = [ "-s" "test" ];

pythonImportsCheck = [ "bitstring" ];

Expand Down
18 changes: 11 additions & 7 deletions pkgs/development/python-modules/clevercsv/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
, regex
, tabview
, python
, unittestCheckHook
}:

buildPythonPackage rec {
Expand All @@ -33,26 +34,29 @@ buildPythonPackage rec {
tabview
];

checkInputs = [ unittestCheckHook ];

pythonImportsCheck = [
"clevercsv"
"clevercsv.cparser"
];

checkPhase = ''
preCheck = ''
# by linking the installed version the tests also have access to compiled native libraries
rm -r clevercsv
ln -s $out/${python.sitePackages}/clevercsv/ clevercsv
# their ci only runs unit tests, there are also integration and fuzzing tests
${python.interpreter} -m unittest discover -v -f -s ./tests/test_unit
'';

# their ci only runs unit tests, there are also integration and fuzzing tests
unittestFlagsArray = [ "-v" "-f" "-s" "./tests/test_unit" ];

meta = with lib; {
description = "CleverCSV is a Python package for handling messy CSV files";
longDescription = ''
CleverCSV is a Python package for handling messy CSV files. It provides
a drop-in replacement for the builtin CSV module with improved dialect
detection, and comes with a handy command line application for working
with CSV files.
CleverCSV is a Python package for handling messy CSV files. It provides
a drop-in replacement for the builtin CSV module with improved dialect
detection, and comes with a handy command line application for working
with CSV files.
'';
homepage = "https://github.com/alan-turing-institute/CleverCSV";
changelog = "https://github.com/alan-turing-institute/CleverCSV/blob/master/CHANGELOG.md";
Expand Down
7 changes: 2 additions & 5 deletions pkgs/development/python-modules/contextlib2/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
, fetchPypi
, python
, pythonOlder
, unittestCheckHook
}:

buildPythonPackage rec {
Expand All @@ -17,11 +18,7 @@ buildPythonPackage rec {
hash = "sha256-qx4r/h0B2Wjht+jZAjvFHvNQm7ohe7cwzuOCfh7oKGk=";
};

checkPhase = ''
runHook preCheck
${python.interpreter} -m unittest discover
runHook postCheck
'';
checkInputs = [ unittestCheckHook ];

pythonImportsCheck = [
"contextlib2"
Expand Down
10 changes: 6 additions & 4 deletions pkgs/development/python-modules/cvxopt/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
, fetchPypi
, isPyPy
, python
, blas, lapack # build segfaults with 64-bit blas
, blas
, lapack # build segfaults with 64-bit blas
, suitesparse
, unittestCheckHook
, glpk ? null
, gsl ? null
, fftw ? null
Expand Down Expand Up @@ -49,9 +51,9 @@ buildPythonPackage rec {
export CVXOPT_FFTW_INC_DIR=${fftw.dev}/include
'';

checkPhase = ''
${python.interpreter} -m unittest discover -s tests
'';
checkInputs = [ unittestCheckHook ];

unittestFlagsArray = [ "-s" "tests" ];

meta = with lib; {
homepage = "http://cvxopt.org/";
Expand Down
Loading