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