def test_duplicate_yaml_dict_key_ignore(dupe_node, monkeypatch): monkeypatch.setattr(C, 'DUPLICATE_YAML_DICT_KEY', 'ignore') cap = Capture() monkeypatch.setattr(Display(), 'warning', cap) ac = AnsibleConstructor() ac.construct_mapping(dupe_node) assert not cap.called
def test_duplicate_yaml_dict_key_warn(dupe_node, monkeypatch): monkeypatch.setattr(C, 'DUPLICATE_YAML_DICT_KEY', 'warn') cap = Capture() monkeypatch.setattr(Display(), 'warning', cap) ac = AnsibleConstructor() ac.construct_mapping(dupe_node) assert cap.called expected = [(( 'While constructing a mapping from tag:yaml.org,2002:map, line 1, column 1, ' 'found a duplicate dict key (bar). Using last defined value only.', ), {})] assert cap.calls == expected
def test_duplicate_yaml_dict_key_error(dupe_node, monkeypatch, mocker): monkeypatch.setattr(C, 'DUPLICATE_YAML_DICT_KEY', 'error') ac = AnsibleConstructor() pytest.raises(ConstructorError, ac.construct_mapping, dupe_node)