<commit_before># pytest-ansible

[![Build Status](https://img.shields.io/travis/jlaska/pytest-ansible.svg)](https://travis-ci.org/jlaska/pytest-ansible)
[![Coverage Status](https://img.shields.io/coveralls/jlaska/pytest-ansible.svg)](https://coveralls.io/r/jlaska/pytest-ansible)
[![Requirements Status](https://requires.io/github/jlaska/pytest-ansible/requirements.svg?branch=master)](https://requires.io/github/jlaska/pytest-ansible/requirements/?branch=master)
[![Version](https://img.shields.io/pypi/v/pytest-ansible.svg)](https://pypi.python.org/pypi/pytest-ansible/)
[![Downloads](https://img.shields.io/pypi/dm/pytest-ansible.svg)](https://pypi.python.org/pypi/pytest-ansible/)
[![License](https://img.shields.io/pypi/l/pytest-ansible.svg)](https://pypi.python.org/pypi/pytest-ansible/)
[![Supported Python Versions](https://img.shields.io/pypi/pyversions/pytest-ansible.svg)](https://pypi.python.org/pypi/pytest-ansible/)


This repository contains a plugin for ``py.test`` which adds several fixtures
for running ``ansible`` modules, or inspecting ``ansible_facts``.  While one
can simply call out to ``ansible`` using the ``subprocess`` module, having to
parse stdout to determine the outcome of the operation is unpleasant and prone
to error.  With ``pytest-ansible``, modules return JSON data which you can
inspect and act on, much like with an ansible
[playbook](http://docs.ansible.com/playbooks.html).

## Installation

Install this plugin using ``pip``

```bash
    pip install pytest-ansible
```

## Usage

Once installed, the following ``py.test`` command-line parameters are available:

```bash
py.test \
    [--ansible-inventory <path_to_inventory>] \
    [--ansible-host-pattern <host-pattern>] \
    [--ansible-connection <plugin>] \
    [--ansible-module-path <path_to_modules] \
    [--ansible-user <username>] \
    [--ansible-sudo] \
    [--ansible-sudo-user <username>]
```

The following fixtures are available:


### Fixture ``ansible_adhoc``

The `ansible_adhoc` fixture returns a function used to initialize a `HostManager` object.

```python
def test_all_the_pings(ansible_adhoc):
    result = ansible_adhoc().all.ping()
    assert result.is_successful

```

### Fixture ``localhost``

The `localhost` fixture is a convenience fixture that surfaces
a `ModuleDispatcher` instance for ansible host running `pytest`.  This is
convenient when using ansible modules that typically run on the local machine,
such as cloud modules (ec2, gce etc...).<commit_msg>Update supported parameters<commit_after># pytest-ansible

[![Build Status](https://img.shields.io/travis/jlaska/pytest-ansible.svg)](https://travis-ci.org/jlaska/pytest-ansible)
[![Coverage Status](https://img.shields.io/coveralls/jlaska/pytest-ansible.svg)](https://coveralls.io/r/jlaska/pytest-ansible)
[![Requirements Status](https://requires.io/github/jlaska/pytest-ansible/requirements.svg?branch=master)](https://requires.io/github/jlaska/pytest-ansible/requirements/?branch=master)
[![Version](https://img.shields.io/pypi/v/pytest-ansible.svg)](https://pypi.python.org/pypi/pytest-ansible/)
[![Downloads](https://img.shields.io/pypi/dm/pytest-ansible.svg)](https://pypi.python.org/pypi/pytest-ansible/)
[![License](https://img.shields.io/pypi/l/pytest-ansible.svg)](https://pypi.python.org/pypi/pytest-ansible/)
[![Supported Python Versions](https://img.shields.io/pypi/pyversions/pytest-ansible.svg)](https://pypi.python.org/pypi/pytest-ansible/)


This repository contains a plugin for ``py.test`` which adds several fixtures
for running ``ansible`` modules, or inspecting ``ansible_facts``.  While one
can simply call out to ``ansible`` using the ``subprocess`` module, having to
parse stdout to determine the outcome of the operation is unpleasant and prone
to error.  With ``pytest-ansible``, modules return JSON data which you can
inspect and act on, much like with an ansible
[playbook](http://docs.ansible.com/playbooks.html).

## Installation

Install this plugin using ``pip``

```bash
    pip install pytest-ansible
```

## Usage

Once installed, the following ``py.test`` command-line parameters are available:

```bash
py.test \
    [--inventory <path_to_inventory>] \
    [--host-pattern <host-pattern>] \
    [--connection <plugin>] \
    [--module-path <path_to_modules] \
    [--user <username>] \
    [--become] \
    [--become-user <username>] \
    [--become-method <method>] \
    [--limit <limit>] \
    [--check]
```

The following fixtures are available:


### Fixture ``ansible_adhoc``

The `ansible_adhoc` fixture returns a function used to initialize a `HostManager` object.

```python
def test_all_the_pings(ansible_adhoc):
    result = ansible_adhoc().all.ping()
    assert result.is_successful

```

### Fixture ``localhost``

The `localhost` fixture is a convenience fixture that surfaces
a `ModuleDispatcher` instance for ansible host running `pytest`.  This is
convenient when using ansible modules that typically run on the local machine,
such as cloud modules (ec2, gce etc...).
{'fraction_non_alphanumeric': 0.15717994807269822, 'fraction_numerical': 0.0003994407829039345, 'mean_word_length': 4.652370203160271, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 15, 'https://': 28, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '994002', 'n_tokens_mistral': 1744, 'n_tokens_neox': 1657, 'n_words': 368}