1{ lib, buildPythonPackage, pythonOlder, fetchPypi, attrs, hypothesis, py
2, setuptools-scm, setuptools, six, pluggy, funcsigs, isPy3k, more-itertools
3, atomicwrites, mock, writeText, pathlib2, wcwidth, packaging, isPyPy
4}:
5buildPythonPackage rec {
6 version = "4.6.11";
7 pname = "pytest";
8
9 src = fetchPypi {
10 inherit pname version;
11 sha256 = "50fa82392f2120cc3ec2ca0a75ee615be4c479e66669789771f1758332be4353";
12 };
13
14 postPatch = ''
15 substituteInPlace setup.py \
16 --replace "pluggy>=0.12,<1.0" "pluggy>=0.12,<2.0"
17 '';
18
19 nativeCheckInputs = [ hypothesis mock ];
20 buildInputs = [ setuptools-scm ];
21 propagatedBuildInputs = [ attrs py setuptools six pluggy more-itertools atomicwrites wcwidth packaging ]
22 ++ lib.optionals (!isPy3k) [ funcsigs ]
23 ++ lib.optionals (pythonOlder "3.6") [ pathlib2 ];
24
25 doCheck = !isPyPy; # https://github.com/pytest-dev/pytest/issues/3460
26 checkPhase = ''
27 runHook preCheck
28
29 # don't test bash builtins
30 rm testing/test_argcomplete.py
31
32 # determinism - this test writes non deterministic bytecode
33 rm -rf testing/test_assertrewrite.py
34
35 PYTHONDONTWRITEBYTECODE=1 $out/bin/py.test -x testing/ -k "not test_collect_pyargs_with_testpaths"
36 runHook postCheck
37 '';
38
39 # Remove .pytest_cache when using py.test in a Nix build
40 setupHook = writeText "pytest-hook" ''
41 pytestcachePhase() {
42 find $out -name .pytest_cache -type d -exec rm -rf {} +
43 }
44
45 preDistPhases+=" pytestcachePhase"
46
47 # pytest generates it's own bytecode files to improve assertion messages.
48 # These files similar to cpython's bytecode files but are never laoded
49 # by python interpreter directly. We remove them for a few reasons:
50 # - files are non-deterministic: https://github.com/NixOS/nixpkgs/issues/139292
51 # (file headers are generatedt by pytest directly and contain timestamps)
52 # - files are not needed after tests are finished
53 pytestRemoveBytecodePhase () {
54 # suffix is defined at:
55 # https://github.com/pytest-dev/pytest/blob/4.6.11/src/_pytest/assertion/rewrite.py#L32-L47
56 find $out -name "*-PYTEST.py[co]" -delete
57 }
58 preDistPhases+=" pytestRemoveBytecodePhase"
59 '';
60
61 meta = with lib; {
62 homepage = "https://docs.pytest.org";
63 description = "Framework for writing tests";
64 maintainers = with maintainers; [ domenkozar lovek323 madjar lsix ];
65 license = licenses.mit;
66 platforms = platforms.unix;
67 };
68}