1{ lib
2, buildPythonPackage
3, callPackage
4, pythonOlder
5, fetchPypi
6, isPyPy
7, writeText
8
9# build
10, setuptools-scm
11
12# propagates
13, attrs
14, exceptiongroup
15, iniconfig
16, packaging
17, pluggy
18, py
19, tomli
20}:
21
22buildPythonPackage rec {
23 pname = "pytest";
24 version = "7.2.1";
25 format = "pyproject";
26
27 src = fetchPypi {
28 inherit pname version;
29 hash = "sha256-1F4JUvNyckGRi4/Q83b1/2swHMB3fG+aVWk1yS2KfUI=";
30 };
31
32 outputs = [
33 "out"
34 "testout"
35 ];
36
37 nativeBuildInputs = [
38 setuptools-scm
39 ];
40
41 propagatedBuildInputs = [
42 attrs
43 iniconfig
44 packaging
45 pluggy
46 py
47 tomli
48 ] ++ lib.optionals (pythonOlder "3.11") [
49 exceptiongroup
50 ];
51
52 postInstall = ''
53 mkdir $testout
54 cp -R testing $testout/testing
55 '';
56
57 doCheck = false;
58 passthru.tests.pytest = callPackage ./tests.nix { };
59
60 # Remove .pytest_cache when using py.test in a Nix build
61 setupHook = writeText "pytest-hook" ''
62 pytestcachePhase() {
63 find $out -name .pytest_cache -type d -exec rm -rf {} +
64 }
65 preDistPhases+=" pytestcachePhase"
66
67 # pytest generates it's own bytecode files to improve assertion messages.
68 # These files similar to cpython's bytecode files but are never laoded
69 # by python interpreter directly. We remove them for a few reasons:
70 # - files are non-deterministic: https://github.com/NixOS/nixpkgs/issues/139292
71 # (file headers are generatedt by pytest directly and contain timestamps)
72 # - files are not needed after tests are finished
73 pytestRemoveBytecodePhase () {
74 # suffix is defined at:
75 # https://github.com/pytest-dev/pytest/blob/7.2.1/src/_pytest/assertion/rewrite.py#L51-L53
76 find $out -name "*-pytest-*.py[co]" -delete
77 }
78 preDistPhases+=" pytestRemoveBytecodePhase"
79 '';
80
81 pythonImportsCheck = [
82 "pytest"
83 ];
84
85 meta = with lib; {
86 description = "Framework for writing tests";
87 homepage = "https://docs.pytest.org";
88 changelog = "https://github.com/pytest-dev/pytest/releases/tag/${version}";
89 maintainers = with maintainers; [ domenkozar lovek323 madjar lsix ];
90 license = licenses.mit;
91 };
92}