1{
2 lib,
3 stdenv,
4 ansible-compat,
5 ansible-core,
6 buildPythonPackage,
7 coreutils,
8 fetchFromGitHub,
9 packaging,
10 pytest,
11 pytest-plus,
12 pytest-sugar,
13 pytest-xdist,
14 pytestCheckHook,
15 pythonOlder,
16 setuptools,
17 setuptools-scm,
18}:
19
20buildPythonPackage rec {
21 pname = "pytest-ansible";
22 version = "25.8.0";
23 pyproject = true;
24
25 disabled = pythonOlder "3.10";
26
27 src = fetchFromGitHub {
28 owner = "ansible";
29 repo = "pytest-ansible";
30 tag = "v${version}";
31 hash = "sha256-y90dvIY0Kvjvc7SYXgtAwNsP/D64k4pJ6rH+v79D1dM=";
32 };
33
34 postPatch = ''
35 substituteInPlace inventory \
36 --replace-fail '/usr/bin/env' '${lib.getExe' coreutils "env"}'
37 '';
38
39 build-system = [
40 setuptools
41 setuptools-scm
42 ];
43
44 buildInputs = [ pytest ];
45
46 dependencies = [
47 ansible-core
48 ansible-compat
49 packaging
50 pytest-plus
51 pytest-sugar
52 pytest-xdist
53 ];
54
55 nativeCheckInputs = [ pytestCheckHook ];
56
57 preCheck = ''
58 export HOME=$TMPDIR
59 '';
60
61 enabledTestPaths = [ "tests/" ];
62
63 disabledTests = [
64 # pytest unrecognized arguments in test_pool.py
65 "test_ansible_test"
66 # Host unreachable in the inventory
67 "test_become"
68 # [Errno -3] Temporary failure in name resolution
69 "test_connection_failure_v2"
70 "test_connection_failure_extra_inventory_v2"
71 ]
72 ++ lib.optionals stdenv.hostPlatform.isDarwin [
73 # These tests fail in the Darwin sandbox
74 "test_ansible_facts"
75 "test_func"
76 "test_param_override_with_marker"
77 ];
78
79 disabledTestPaths = [
80 # Test want s to execute pytest in a subprocess
81 "tests/integration/test_molecule.py"
82 ]
83 ++ lib.optionals stdenv.hostPlatform.isDarwin [
84 # These tests fail in the Darwin sandbox
85 "tests/test_adhoc.py"
86 "tests/test_adhoc_result.py"
87 ]
88 ++ lib.optionals (lib.versionAtLeast ansible-core.version "2.16") [
89 # Test fail in the NixOS environment
90 "tests/test_adhoc.py"
91 ];
92
93 pythonImportsCheck = [ "pytest_ansible" ];
94
95 meta = with lib; {
96 description = "Plugin for pytest to simplify calling ansible modules from tests or fixtures";
97 homepage = "https://github.com/jlaska/pytest-ansible";
98 changelog = "https://github.com/ansible-community/pytest-ansible/releases/tag/${src.tag}";
99 license = licenses.mit;
100 maintainers = with maintainers; [
101 tjni
102 robsliwi
103 ];
104 };
105}