21 # optional-dependencies
31 self = buildPythonPackage rec {
37 inherit pname version;
38 hash = "sha256-LPAAWSLGrOSj4uyLQIDrDZdT/ckxB0FTMvUM6eeZQoA=";
51 propagatedBuildInputs =
57 ++ lib.optionals (pythonOlder "3.11") [
62 optional-dependencies = {
77 cp -R testing $testout/testing
81 passthru.tests.pytest = callPackage ./tests.nix { pytest = self; };
83 # Remove .pytest_cache when using py.test in a Nix build
84 setupHook = writeText "pytest-hook" ''
86 find $out -name .pytest_cache -type d -exec rm -rf {} +
88 appendToVar preDistPhases pytestcachePhase
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
101 appendToVar preDistPhases pytestRemoveBytecodePhase
104 pythonImportsCheck = [ "pytest" ];
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; [
116 license = licenses.mit;