at 22.05-pre 3.1 kB view raw
1{ lib, buildPythonPackage, pythonOlder, fetchPypi, isPy3k, isPyPy 2, atomicwrites 3, attrs 4, hypothesis 5, iniconfig 6, more-itertools 7, packaging 8, pathlib2 9, pluggy 10, py 11, pygments 12, setuptools 13, setuptools-scm 14, six 15, toml 16, wcwidth 17, writeText 18}: 19 20buildPythonPackage rec { 21 pname = "pytest"; 22 version = "6.2.5"; 23 disabled = !isPy3k; 24 25 src = fetchPypi { 26 inherit pname version; 27 sha256 = "131b36680866a76e6781d13f101efb86cf674ebb9762eb70d3082b6f29889e89"; 28 }; 29 30 postPatch = '' 31 substituteInPlace setup.cfg \ 32 --replace "pluggy>=0.12,<1.0.0a1" "pluggy>=0.23,<2.0" 33 ''; 34 35 nativeBuildInputs = [ setuptools-scm ]; 36 37 propagatedBuildInputs = [ 38 atomicwrites 39 attrs 40 iniconfig 41 more-itertools 42 packaging 43 pluggy 44 py 45 setuptools 46 six 47 toml 48 wcwidth 49 ] ++ lib.optionals (pythonOlder "3.6") [ pathlib2 ]; 50 51 checkInputs = [ 52 hypothesis 53 pygments 54 ]; 55 56 doCheck = !isPyPy; # https://github.com/pytest-dev/pytest/issues/3460 57 58 preCheck = '' 59 # don't test bash builtins 60 rm testing/test_argcomplete.py 61 ''; 62 63 # Ignored file https://github.com/pytest-dev/pytest/pull/5605#issuecomment-522243929 64 # test_missing_required_plugins will emit deprecation warning which is treated as error 65 checkPhase = '' 66 runHook preCheck 67 $out/bin/py.test -x testing/ \ 68 --ignore=testing/test_junitxml.py \ 69 -k "not test_collect_pyargs_with_testpaths and not test_missing_required_plugins" 70 71 # tests leave behind unreproducible pytest binaries in the output directory, remove: 72 find $out/lib -name "*-pytest-${version}.pyc" -delete 73 # specifically testing/test_assertion.py and testing/test_assertrewrite.py leave behind those: 74 find $out/lib -name "*opt-2.pyc" -delete 75 76 runHook postCheck 77 ''; 78 79 # Remove .pytest_cache when using py.test in a Nix build 80 setupHook = writeText "pytest-hook" '' 81 pytestcachePhase() { 82 find $out -name .pytest_cache -type d -exec rm -rf {} + 83 } 84 preDistPhases+=" pytestcachePhase" 85 86 # pytest generates it's own bytecode files to improve assertion messages. 87 # These files similar to cpython's bytecode files but are never laoded 88 # by python interpreter directly. We remove them for a few reasons: 89 # - files are non-deterministic: https://github.com/NixOS/nixpkgs/issues/139292 90 # (file headers are generatedt by pytest directly and contain timestamps) 91 # - files are not needed after tests are finished 92 pytestRemoveBytecodePhase () { 93 # suffix is defined at: 94 # https://github.com/pytest-dev/pytest/blob/6.2.5/src/_pytest/assertion/rewrite.py#L51-L53 95 find $out -name "*-pytest-*.py[co]" -delete 96 } 97 preDistPhases+=" pytestRemoveBytecodePhase" 98 ''; 99 100 pythonImportsCheck = [ 101 "pytest" 102 ]; 103 104 meta = with lib; { 105 description = "Framework for writing tests"; 106 homepage = "https://docs.pytest.org"; 107 changelog = "https://github.com/pytest-dev/pytest/releases/tag/${version}"; 108 maintainers = with maintainers; [ domenkozar lovek323 madjar lsix ]; 109 license = licenses.mit; 110 }; 111}