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