craft_cli.pytest_plugin module¶
Different fixtures for easier testability of Craft CLI services.
- craft_cli.pytest_plugin.init_emitter(monkeypatch)[source]¶
Ensure
emit
is always clean, and initiated (in test mode).Note that the
init
is done in the current instance that all modules already acquired.This is an “autouse” fixture, so it just works, no need to declare it in your tests.
- class craft_cli.pytest_plugin.RecordingEmitter[source]¶
Bases:
object
Record what is shown using the emitter and provide a nice API for tests.
This class is NOT meant to be used directly, please use the
emitter
fixture instead which provides an instance of this class with context properly set up.- assert_message(expected_text, regex=False)[source]¶
Check the ‘message’ method was properly used.
It verifies that the method was called at least once with the expected text.
If ‘regex’ is True, the expected text will be used as a regular expression.
- assert_progress(expected_text, permanent=None, regex=False)[source]¶
Check the ‘progress’ method was properly used.
It verifies that the method was called at least once with the expected text (with the given ‘permanent’ flag).
If ‘regex’ is True, the expected text will be used as a regular expression.
- assert_verbose(expected_text, regex=False)[source]¶
Check the ‘verbose’ method was properly used.
It verifies that the method was called at least once with the expected text.
If ‘regex’ is True, the expected text will be used as a regular expression.
- assert_debug(expected_text, regex=False)[source]¶
Check the ‘debug’ method was properly used.
It verifies that the method was called at least once with the expected text.
If ‘regex’ is True, the expected text will be used as a regular expression.
- assert_trace(expected_text, regex=False)[source]¶
Check the ‘trace’ method was properly used.
It verifies that the method was called at least once with the expected text.
If ‘regex’ is True, the expected text will be used as a regular expression.
- assert_messages(texts)[source]¶
Check that the ‘message’ method was called several times with the given texts.
This is helper for a common case that happen in multiline commands results where ‘message’ is called several times.
- assert_error(error: CraftError) CraftError [source]¶
Check that the ‘error’ method was called with the given error.