Metadata-Version: 2.1
Name: pytest-operator
Version: 0.10.0
Summary: Fixtures for Operators
Home-page: https://github.com/charmed-kubernetes/pytest-operator
Author: Cory Johns
Author-email: cory.johns@canonical.com
License: MIT license
Keywords: pytest,py.test,operators,yaml,asyncio
Platform: UNKNOWN
Classifier: Framework :: Pytest
Classifier: Programming Language :: Python
Classifier: Topic :: Software Development :: Testing
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Description-Content-Type: text/markdown
License-File: LICENSE

# pytest-operator

PyTest plugin to make it easy to create integration tests for Operator Charms.

## Usage

Include `pytest-operator` in the `deps` of your `tox.ini` file:

```ini
[testenv]
deps =
  pytest
  pytest-operator
```

Then, just start using the `ops_test` fixture in your async tests.  This
module-scoped fixture provides a libjuju Model, helpers to build charms for
testing, and the ability to abort testing so that the remaining tests in the
module are automatically xfailed (you can also mark a test so that this happens
automatically if the test fails; this is typically used on the initial deployment
test, where subsequent tests depend on the deployment having succeeded).

As an additional nicety, you don't have to explicitly mark an async test with
`@pytest.mark.asyncio`; if it's a test function / method and it's async, it
will be marked automatically.

Example:

```python
import pytest


@pytest.mark.abort_on_fail
async def test_build_and_deploy(ops_test):
    my_charm = await ops_test.build_charm(".")
    await ops_test.model.deploy(my_charm)
    await ops_test.model.wait_for_idle()


async def test_status(ops_test):
    assert ops_test.model.applications["my-charm"].units[0].workload_status == "active"
```

## Reference

More details can be found in [the reference docs](docs/reference.md).


