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