pytest-operator provides a set of pytest fixtures designed to simplify the testing of Charmed Operators, particularly for integration and functional tests. It abstracts away much of the complexity of deploying and managing Juju models and charms within a test environment. The current version is 0.43.2, and it maintains an active release cadence with frequent patch updates and occasional minor feature releases.
pip install pytest-operatorVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates a basic integration test using `pytest-operator`. It shows how to declare the plugin in `conftest.py`, build a charm using `ops_test.build_charm()`, deploy it to a temporary Juju model, and assert its status. Ensure `charmcraft` is installed if you are building charms locally.
Be aware that external Juju models are not affected. If you need to debug a model, you can set `PYTEST_OPERATOR_KEEP_MODEL=true` in your environment, but manual cleanup will be required.
Install charmcraft: `snap install charmcraft --classic` or ensure it's in your virtual environment if using a tool like `pipx`.
Design tests to be as efficient as possible. Leverage shared fixtures (e.g., a single deployment for multiple tests in a module if safe) and consider using `pytest-xdist` for parallel execution, if applicable, for larger test suites.