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