-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add --verbose flag to pass -vv to spread from charmcraft test #1988
base: main
Are you sure you want to change the base?
Conversation
53b9019
to
7864269
Compare
I'm pleasantly surprised that this doesn't conflict with the |
@@ -84,6 +90,9 @@ def run(self, parsed_args: argparse.Namespace): | |||
else: | |||
cmd = ["spread"] | |||
|
|||
if vars(parsed_args).get("verbose"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if vars(parsed_args).get("verbose"): | |
if emit.get_mode().value >= EmitterMode.VERBOSE.value: |
(You'll need to import EmitterMode
from craft_cli above, but then you can remove the add_argument
too)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you also add tests? This unit test should be fine in tests/unit/commands/test_test.py
:
# Copyright 2024 Canonical Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# For further info, check https://github.com/canonical/charmcraft
"""Unit tests for the test command."""
import argparse
from craft_cli import EmitterMode, emit
import pytest
from charmcraft.application.commands.test import TestCommand
from charmcraft.application.main import APP_METADATA
@pytest.mark.parametrize("emitter_mode", [EmitterMode.VERBOSE, EmitterMode.DEBUG, EmitterMode.TRACE])
def test_spread_verbose(fp, capsys, service_factory, emitter_mode: EmitterMode) -> None:
emit._mode = emitter_mode
fp.register(["spread", "-vv", "wololo"])
cmd = TestCommand({"app": APP_METADATA, "services": service_factory})
args = argparse.Namespace(spread_tasks=["wololo"])
cmd.run(args)
@pytest.mark.parametrize("emitter_mode", [EmitterMode.QUIET, EmitterMode.BRIEF])
def test_spread_not_verbose(fp, capsys, service_factory, emitter_mode: EmitterMode) -> None:
emit._mode = emitter_mode
fp.register(["spread", "wololo"])
cmd = TestCommand({"app": APP_METADATA, "services": service_factory})
args = argparse.Namespace(spread_tasks=["wololo"])
cmd.run(args)
Adding @cmatsuoka since this is really his call, not mine. |
It is useful in CI to see the full verbose output from spread commands.
This PR adds an optional flag to the
charmcraft test
command.charmcraft test --verbose foo:bar/baz/qux:var
-->spread -vv foo:bar/baz/qux:var