at 24.11-pre 2.5 kB view raw
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 31buildPythonPackage rec { 32 pname = "pytest"; 33 version = "8.1.1"; 34 pyproject = true; 35 36 src = fetchPypi { 37 inherit pname version; 38 hash = "sha256-rJeBQadZSJSIF9NgKXt6rg/LnW/2vJ7G1RS4XVplwEQ="; 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 passthru.optional-dependencies = { 63 testing = [ 64 argcomplete 65 attrs 66 hypothesis 67 mock 68 nose 69 pygments 70 requests 71 setuptools 72 xmlschema 73 ]; 74 }; 75 76 postInstall = '' 77 mkdir $testout 78 cp -R testing $testout/testing 79 ''; 80 81 doCheck = false; 82 passthru.tests.pytest = callPackage ./tests.nix { }; 83 84 # Remove .pytest_cache when using py.test in a Nix build 85 setupHook = writeText "pytest-hook" '' 86 pytestcachePhase() { 87 find $out -name .pytest_cache -type d -exec rm -rf {} + 88 } 89 preDistPhases+=" pytestcachePhase" 90 91 # pytest generates it's own bytecode files to improve assertion messages. 92 # These files similar to cpython's bytecode files but are never laoded 93 # by python interpreter directly. We remove them for a few reasons: 94 # - files are non-deterministic: https://github.com/NixOS/nixpkgs/issues/139292 95 # (file headers are generatedt by pytest directly and contain timestamps) 96 # - files are not needed after tests are finished 97 pytestRemoveBytecodePhase () { 98 # suffix is defined at: 99 # https://github.com/pytest-dev/pytest/blob/7.2.1/src/_pytest/assertion/rewrite.py#L51-L53 100 find $out -name "*-pytest-*.py[co]" -delete 101 } 102 preDistPhases+=" pytestRemoveBytecodePhase" 103 ''; 104 105 pythonImportsCheck = [ "pytest" ]; 106 107 meta = with lib; { 108 description = "Framework for writing tests"; 109 homepage = "https://docs.pytest.org"; 110 changelog = "https://github.com/pytest-dev/pytest/releases/tag/${version}"; 111 maintainers = with maintainers; [ 112 domenkozar 113 lovek323 114 madjar 115 lsix 116 ]; 117 license = licenses.mit; 118 }; 119}