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.

pause()[source]

Mimics the pause context manager, storing the state to simplify tests.

record(method_name, args, kwargs)[source]

Record the method call and its specific parameters.

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.

assert_interactions(expected_call_list)[source]

Check that the expected call list happen at some point between all stored calls.

If None is passed, asserts that no message was emitted.

craft_cli.pytest_plugin.emitter(monkeypatch)[source]

Provide a helper to test everything that was shown using the Emitter.