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