1{ 2 lib, 3 buildPythonPackage, 4 callPackage, 5 pythonOlder, 6 fetchPypi, 7 writeText, 8 9 # build-system 10 setuptools, 11 setuptools-scm, 12 13 # dependencies 14 attrs, 15 exceptiongroup, 16 iniconfig, 17 packaging, 18 pluggy, 19 tomli, 20 21 # optional-dependencies 22 argcomplete, 23 hypothesis, 24 mock, 25 pygments, 26 requests, 27 xmlschema, 28}: 29 30let 31 self = buildPythonPackage rec { 32 pname = "pytest"; 33 version = "7.4.4"; 34 pyproject = true; 35 36 src = fetchPypi { 37 inherit pname version; 38 hash = "sha256-LPAAWSLGrOSj4uyLQIDrDZdT/ckxB0FTMvUM6eeZQoA="; 39 }; 40 41 outputs = [ 42 "out" 43 "testout" 44 ]; 45 46 nativeBuildInputs = [ 47 setuptools 48 setuptools-scm 49 ]; 50 51 propagatedBuildInputs = 52 [ 53 iniconfig 54 packaging 55 pluggy 56 ] 57 ++ lib.optionals (pythonOlder "3.11") [ 58 exceptiongroup 59 tomli 60 ]; 61 62 optional-dependencies = { 63 testing = [ 64 argcomplete 65 attrs 66 hypothesis 67 mock 68 pygments 69 requests 70 setuptools 71 xmlschema 72 ]; 73 }; 74 75 postInstall = '' 76 mkdir $testout 77 cp -R testing $testout/testing 78 ''; 79 80 doCheck = false; 81 passthru.tests.pytest = callPackage ./tests.nix { pytest = self; }; 82 83 # Remove .pytest_cache when using py.test in a Nix build 84 setupHook = writeText "pytest-hook" '' 85 pytestcachePhase() { 86 find $out -name .pytest_cache -type d -exec rm -rf {} + 87 } 88 appendToVar preDistPhases pytestcachePhase 89 90 # pytest generates it's own bytecode files to improve assertion messages. 91 # These files similar to cpython's bytecode files but are never laoded 92 # by python interpreter directly. We remove them for a few reasons: 93 # - files are non-deterministic: https://github.com/NixOS/nixpkgs/issues/139292 94 # (file headers are generatedt by pytest directly and contain timestamps) 95 # - files are not needed after tests are finished 96 pytestRemoveBytecodePhase () { 97 # suffix is defined at: 98 # https://github.com/pytest-dev/pytest/blob/7.2.1/src/_pytest/assertion/rewrite.py#L51-L53 99 find $out -name "*-pytest-*.py[co]" -delete 100 } 101 appendToVar preDistPhases pytestRemoveBytecodePhase 102 ''; 103 104 pythonImportsCheck = [ "pytest" ]; 105 106 meta = with lib; { 107 description = "Framework for writing tests"; 108 homepage = "https://docs.pytest.org"; 109 changelog = "https://github.com/pytest-dev/pytest/releases/tag/${version}"; 110 maintainers = with maintainers; [ 111 domenkozar 112 lovek323 113 madjar 114 lsix 115 ]; 116 license = licenses.mit; 117 }; 118 }; 119in 120self