Skip to content
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

Print version on debug verbosity level #765

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/orion/core/cli/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import textwrap

import orion
import orion.core
from orion.core.io.database import DatabaseError
from orion.core.utils.exceptions import (
BranchingEvent,
Expand All @@ -18,6 +19,8 @@
NoNameError,
)

logger = logging.getLogger(__name__)

CLI_DOC_HEADER = "Oríon CLI for asynchronous distributed optimization"


Expand Down Expand Up @@ -71,6 +74,7 @@ def parse(self, argv):
format="%(asctime)-15s::%(levelname)s::%(name)s::%(message)s",
level=levels.get(verbose, logging.DEBUG),
)
logger.debug("Orion version : %s", orion.core.__version__)

if args["command"] is None:
self.parser.parse_args(["--help"])
Expand Down
27 changes: 27 additions & 0 deletions tests/functional/commands/test_verbose_messages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Perform a functional test of the debug verbosity level."""
import logging

import pytest

import orion.core.cli


def test_version_print_debug_verbosity(caplog):
"""Tests that Orion version is printed in debug verbosity level"""

caplog.set_level(logging.DEBUG)

with pytest.raises(SystemExit):
orion.core.cli.main([""])
assert "Orion version : " not in caplog.text
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a good idea to test that the log was effective at the DEBUG level only. Instead of testing with INFO and then with DEBUG you could use record_tuples to verify the level at which the message was logged:

You can also resort to record_tuples if all you want to do is to ensure, that certain messages have been logged under a given logger name with a given severity and message:

def test_foo(caplog):
    logging.getLogger().info("boo %s", "arg")

    assert caplog.record_tuples == [("root", logging.INFO, "boo arg")]

https://docs.pytest.org/en/6.2.x/logging.html#caplog-fixture


caplog.clear()
with pytest.raises(SystemExit):
orion.core.cli.main(["-vv"])
for (loggername, loggerlevel, text) in caplog.record_tuples:
assert not (
text.startswith("Orion version : ") and (loggerlevel != logging.DEBUG)
)
assert "Orion version : " in caplog.text