nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at 22.05 103 lines 2.7 kB view raw
1{ lib 2, buildPythonPackage 3, pythonOlder 4, fetchPypi 5, isPyPy 6, writeText 7 8# build 9, setuptools-scm 10 11# propagates 12, attrs 13, iniconfig 14, packaging 15, pluggy 16, py 17, tomli 18 19# tests 20, hypothesis 21, pygments 22}: 23 24buildPythonPackage rec { 25 pname = "pytest"; 26 version = "7.1.1"; 27 format = "pyproject"; 28 29 src = fetchPypi { 30 inherit pname version; 31 sha256 = "sha256-hBEyyu9rGtF6mv3kbcT2z6WaBflVWq5RUfc73yggymM="; 32 }; 33 34 nativeBuildInputs = [ 35 setuptools-scm 36 ]; 37 38 propagatedBuildInputs = [ 39 attrs 40 iniconfig 41 packaging 42 pluggy 43 py 44 tomli 45 ]; 46 47 checkInputs = [ 48 hypothesis 49 pygments 50 ]; 51 52 doCheck = !isPyPy; # https://github.com/pytest-dev/pytest/issues/3460 53 54 # Ignored file https://github.com/pytest-dev/pytest/pull/5605#issuecomment-522243929 55 # test_missing_required_plugins will emit deprecation warning which is treated as error 56 checkPhase = '' 57 runHook preCheck 58 $out/bin/py.test -x testing/ \ 59 --ignore=testing/test_junitxml.py \ 60 --ignore=testing/test_argcomplete.py \ 61 -k "not test_collect_pyargs_with_testpaths and not test_missing_required_plugins" 62 63 # tests leave behind unreproducible pytest binaries in the output directory, remove: 64 find $out/lib -name "*-pytest-${version}.pyc" -delete 65 # specifically testing/test_assertion.py and testing/test_assertrewrite.py leave behind those: 66 find $out/lib -name "*opt-2.pyc" -delete 67 68 runHook postCheck 69 ''; 70 71 # Remove .pytest_cache when using py.test in a Nix build 72 setupHook = writeText "pytest-hook" '' 73 pytestcachePhase() { 74 find $out -name .pytest_cache -type d -exec rm -rf {} + 75 } 76 preDistPhases+=" pytestcachePhase" 77 78 # pytest generates it's own bytecode files to improve assertion messages. 79 # These files similar to cpython's bytecode files but are never laoded 80 # by python interpreter directly. We remove them for a few reasons: 81 # - files are non-deterministic: https://github.com/NixOS/nixpkgs/issues/139292 82 # (file headers are generatedt by pytest directly and contain timestamps) 83 # - files are not needed after tests are finished 84 pytestRemoveBytecodePhase () { 85 # suffix is defined at: 86 # https://github.com/pytest-dev/pytest/blob/7.1.1/src/_pytest/assertion/rewrite.py#L51-L53 87 find $out -name "*-pytest-*.py[co]" -delete 88 } 89 preDistPhases+=" pytestRemoveBytecodePhase" 90 ''; 91 92 pythonImportsCheck = [ 93 "pytest" 94 ]; 95 96 meta = with lib; { 97 description = "Framework for writing tests"; 98 homepage = "https://docs.pytest.org"; 99 changelog = "https://github.com/pytest-dev/pytest/releases/tag/${version}"; 100 maintainers = with maintainers; [ domenkozar lovek323 madjar lsix ]; 101 license = licenses.mit; 102 }; 103}