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