at master 2.6 kB view raw
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 format = "setuptools"; 27 pname = "pytest"; 28 29 src = fetchPypi { 30 inherit pname version; 31 sha256 = "50fa82392f2120cc3ec2ca0a75ee615be4c479e66669789771f1758332be4353"; 32 }; 33 34 postPatch = '' 35 substituteInPlace setup.py \ 36 --replace "pluggy>=0.12,<1.0" "pluggy>=0.12,<2.0" 37 ''; 38 39 nativeCheckInputs = [ 40 hypothesis 41 mock 42 ]; 43 buildInputs = [ setuptools-scm ]; 44 propagatedBuildInputs = [ 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 lovek323 99 madjar 100 lsix 101 ]; 102 license = licenses.mit; 103 platforms = platforms.unix; 104 }; 105}