Skip to content

Commit

Permalink
Use correct pytest cli (#107)
Browse files Browse the repository at this point in the history
* Use correct pytest cli

* chore: auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
ssbarnea and pre-commit-ci[bot] authored Apr 14, 2023
1 parent cfcb252 commit a073bca
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[![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
This repository contains a plugin for `pytest` 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
Expand All @@ -23,10 +23,10 @@ pip install pytest-ansible

## Usage

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

```bash
py.test \
pytest \
[--inventory <path_to_inventory>] \
[--extra-inventory <path_to_extra_inventory>] \
[--host-pattern <host-pattern>] \
Expand Down Expand Up @@ -60,19 +60,19 @@ JSON](http://docs.ansible.com/ansible/latest/intro_dynamic_inventory.html).
For example,

```bash
py.test --inventory my_inventory.ini --host-pattern all
pytest --inventory my_inventory.ini --host-pattern all
```

or

```bash
py.test --inventory path/to/my/script.py --host-pattern webservers
pytest --inventory path/to/my/script.py --host-pattern webservers
```

or

```bash
py.test --inventory one.example.com,two.example.com --host-pattern all
pytest --inventory one.example.com,two.example.com --host-pattern all
```

In the above examples, the inventory provided at runtime will be used in all
Expand All @@ -91,18 +91,18 @@ we'll use the `ansible_adhoc` fixture.
For example,

```bash
py.test --inventory my_inventory.ini --extra-inventory my_second_inventory.ini --host-pattern host_in_second_inventory
pytest --inventory my_inventory.ini --extra-inventory my_second_inventory.ini --host-pattern host_in_second_inventory
```

### Fixture `ansible_adhoc`

The `ansible_adhoc` fixture returns a function used to initialize
a `HostManager` object. The `ansible_adhoc` fixture will default to parameters
supplied to the `py.test` command-line, but also allows one to provide keyword
supplied to the `pytest` command-line, but also allows one to provide keyword
arguments used to initialize the inventory.

The example below demonstrates basic usage with options supplied at run-time to
`py.test`.
`pytest`.

```python
def test_all_the_pings(ansible_adhoc):
Expand Down Expand Up @@ -180,7 +180,7 @@ def test_do_something_cloudy(localhost, ansible_adhoc):

The `ansible_module` fixture allows tests and fixtures to call [ansible
modules](http://docs.ansible.com/modules.html). Unlike the `ansible_adhoc`
fixture, this fixture only uses the options supplied to `py.test` at run time.
fixture, this fixture only uses the options supplied to `pytest` at run time.

A very basic example demonstrating the ansible [`ping` module](http://docs.ansible.com/ping_module.html):

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ build-backend = "setuptools.build_meta"
requires-python = ">=3.9"
dynamic = ["version", "dependencies", "optional-dependencies"]
name = "pytest-ansible"
description = "Plugin for py.test to simplify calling ansible modules from tests or fixtures"
description = "Plugin for pytest to simplify calling ansible modules from tests or fixtures"
readme = "README.md"
authors = [{ "name" = "Ansible by Red Hat", "email" = "info@ansible.com" }]
maintainers = [{ "name" = "Ansible by Red Hat", "email" = "info@ansible.com" }]
Expand Down
10 changes: 5 additions & 5 deletions tests/test_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@


def test_plugin_help(testdir):
"""Verifies expected output from of py.test --help"""
"""Verifies expected output from of pytest --help"""

result = testdir.runpytest("--help")
result.stdout.fnmatch_lines(
Expand All @@ -60,7 +60,7 @@ def test_plugin_help(testdir):


def test_plugin_markers(testdir):
"""Verifies expected output from of py.test --markers"""
"""Verifies expected output from of pytest --markers"""

result = testdir.runpytest("--markers")
result.stdout.fnmatch_lines(
Expand Down Expand Up @@ -177,7 +177,7 @@ def test_func(ansible_module):
*["--ansible-inventory", "bogus", "--ansible-host-pattern", "all"]
)

# Assert py.test exit code
# Assert pytest exit code
assert result.ret == EXIT_TESTSFAILED

# Assert expected error output
Expand Down Expand Up @@ -218,7 +218,7 @@ def test_func(ansible_module):
]
)

# Assert py.test exit code
# Assert pytest exit code
assert result.ret == EXIT_OK

# Assert mock open called on provided file
Expand All @@ -245,7 +245,7 @@ def test_func(ansible_module):
*["-vvvvvs", "--ansible-inventory", "bogus", "--ansible-host-pattern", "all"]
)

# Assert py.test exit code
# Assert pytest exit code
assert result.ret == EXIT_OK

# There appear to be '\n' newline characters within the output. Using the join on errlines flattens the string for
Expand Down

0 comments on commit a073bca

Please sign in to comment.