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