tests.test_logging moduleΒΆ

tests.test_logging.CUSTOM_FORMAT = '{levelname} | {name} | {message}'ΒΆ

A format to tell a logger set up on purpose from the default of Click Extra.

tests.test_logging.run_handlers()[source]ΒΆ

The handlers of Click Extra attached to the root logger right now.

tests.test_logging.test_level_default_order()[source]ΒΆ
tests.test_logging.test_root_logger_defaults()[source]ΒΆ

Check our internal default is aligned to Python’s root logger.

tests.test_logging.test_integrated_verbosity_options(invoke, cmd_decorator, cmd_type, args, expected_level, assert_output_regex)[source]ΒΆ
tests.test_logging.test_custom_verbosity_option_name(invoke, args, assert_output_regex)[source]ΒΆ
tests.test_logging.test_custom_verbose_option_name(invoke, args, assert_output_regex)[source]ΒΆ
tests.test_logging.test_custom_quiet_option_name(invoke, args)[source]ΒΆ
tests.test_logging.test_counter_trace_agrees_with_its_count(invoke, args, trace)[source]ΒΆ

The -v/-q trace says one level in the singular, and more in the plural.

tests.test_logging.test_unrecognized_verbosity_level(invoke, cmd_decorator, cmd_type)[source]ΒΆ
tests.test_logging.test_standalone_option_default_logger(invoke, cmd_decorator, option_decorator, args, expected_level, assert_output_regex)[source]ΒΆ

Checks: - option affect log level - the default logger is root - the default logger message format - level names are colored - log level is propagated to all other loggers

tests.test_logging.test_default_logger_param(invoke, logger_param, params)[source]ΒΆ

Passing a logger instance or name to the default_logger parameter works.

tests.test_logging.test_new_logger_name_passing(invoke)[source]ΒΆ

Test extra logger with custom format, passed to the option by its name.

tests.test_logging.test_new_logger_object_passing(invoke)[source]ΒΆ

Test extra logger with custom format, passed as an object to the option.

tests.test_logging.restored_root_logger()[source]ΒΆ

Put the root logger back the way the test found it.

new_logger() naming no logger reconfigures the process-wide root one through basicConfig(force=True), which drops whatever handlers were already attached. Nothing in logging undoes that, so a test doing it once decides how every later test in the same worker renders: leaving the handler behind is what made test_logger_propagation fail whenever this module’s root-logger test ran before it.

A run of a plain Click command that failed while parsing keeps its hold on the handler of Click Extra until its context is collected. Collecting first keeps that handler out of the saved list, which would otherwise attach it again once the test is over.

class tests.test_logging.RecordingHandler[source]ΒΆ

Bases: Handler

Stand-in for the handler of an application: keeps the messages it receives.

Initializes the instance - basically setting the formatter to None and the filter list to empty.

emit(record)[source]ΒΆ

Do whatever it takes to actually log the specified logging record.

This version is intended to be implemented by subclasses and so raises a NotImplementedError.

close()[source]ΒΆ

Tidy up any resources used by the handler.

This version removes the handler from an internal map of handlers, _handlers, which is used for handler lookup by name. Subclasses should ensure that this gets called from overridden close() methods.

tests.test_logging.app_handler(restored_root_logger)[source]ΒΆ

A handler attached to the root logger before any command is defined.

This is the state an application leaves the root logger in before it imports a CLI, and the one pytest leaves it in with its own capture handlers.

tests.test_logging.test_new_logger_root_config(invoke, restored_root_logger)[source]ΒΆ

Modify the root logger via new_logger()

tests.test_logging.test_logger_propagation(invoke)[source]ΒΆ
tests.test_logging.test_decorating_a_command_leaves_the_root_logger_alone(cmd_decorator, app_handler)[source]ΒΆ

Defining a command changes neither the handlers nor the level of root.

A command is defined when its module is imported: the handlers found there belong to whoever imports it.

tests.test_logging.test_unregistered_logger_name_is_set_up_without_the_root_logger(app_handler)[source]ΒΆ

A name unknown to logging gets a logger of its own when the option is built. The root logger stays out of it.

tests.test_logging.extra_command(body)[source]ΒΆ

A Click Extra command, which carries the verbosity options by default.

tests.test_logging.extra_group(body)[source]ΒΆ

A Click Extra group: its subcommand carries the verbosity options too.

tests.test_logging.click_command(body)[source]ΒΆ

A plain Click command borrowing the verbosity option.

tests.test_logging.click_command_with_its_own_logger(body)[source]ΒΆ

A plain Click command whose verbosity option sets a logger of its own.

tests.test_logging.click_command_without_verbosity(body)[source]ΒΆ

A plain Click command borrowing an option other than the verbosity ones.

tests.test_logging.test_run_adds_one_handler_beside_the_others(invoke, app_handler, build)[source]ΒΆ

A run prints through one handler of Click Extra, added beside the handlers already on the root logger, and gone once the run is over.

The handler of the application stays attached all along, and receives the record too: a console handler there prints it a second time.

tests.test_logging.test_each_run_gets_the_handler(invoke, app_handler)[source]ΒΆ

The handler leaves with a run, and the next run gets one again.

tests.test_logging.test_record_of_an_earlier_option_is_printed(invoke, app_handler)[source]ΒΆ

The handler is attached before Click processes any option, so a record emitted by an option processed ahead of the verbosity ones is printed.

tests.test_logging.test_record_after_a_run_is_not_printed(invoke, app_handler, capsys)[source]ΒΆ

Once a run is over, Click Extra prints nothing of what the process logs.

tests.test_logging.test_caplog_captures_the_records_of_a_command_defined_in_a_test(invoke, caplog)[source]ΒΆ

pytest attaches its capture handlers to the root logger before the test body runs: a command defined in that body must leave them in place.

tests.test_logging.test_file_handler_of_the_root_logger_keeps_writing(invoke, restored_root_logger, tmp_path)[source]ΒΆ

No handler of the root logger is closed, at any point.

A file handler opened in w mode never opens its file again once closed, which is the mode of the one behind pytest’s --log-file.

tests.test_logging.test_handler_leaves_however_the_run_ends(invoke, app_handler, args, exit_code)[source]ΒΆ

A Click Extra command gives the handler back the moment its run ends, whatever the run ends on.

tests.test_logging.test_failed_run_of_a_click_command_gives_the_handler_back_when_collected(invoke, app_handler)[source]ΒΆ

A plain Click command has no hook on a run that fails while parsing: the handler leaves once Python collects the context of that run.

tests.test_logging.test_run_keeps_its_handler_when_a_failed_run_is_collected(invoke, app_handler)[source]ΒΆ

The context of a failed run may be collected in the middle of a later run, which then still needs the handler they share.

tests.test_logging.test_failed_run_collected_while_a_record_is_handled(invoke, restored_root_logger)[source]ΒΆ

The context of a failed run may be collected while the root logger hands a record to its handlers: the handlers after the one of that run still get it.

tests.test_logging.test_nested_runs_share_one_handler(invoke, app_handler, inner_args)[source]ΒΆ

A run started from within another one prints through the same handler, and leaves it to the run around it when it ends.

tests.test_logging.test_resilient_parsing_adds_no_handler(app_handler)[source]ΒΆ

Click parses without side effects to complete a command line: the root logger gets no handler then.

tests.test_logging.test_root_logger_set_up_on_purpose_is_left_as_it_is(invoke, restored_root_logger, set_up, build)[source]ΒΆ

A command left on the root logger keeps the format new_logger() or basicConfig() gave it, and adds no handler of its own.

tests.test_logging.test_handlers_given_to_new_logger_replace_the_run_handler(invoke, restored_root_logger)[source]ΒΆ

new_logger() given the handlers of the caller is how an application keeps the handler of Click Extra off the root logger.

tests.test_logging.test_new_logger_replaces_the_handlers_of_the_root_logger(restored_root_logger, force, replaced)[source]ΒΆ

Left on its default name, new_logger() removes and closes every handler of the root logger, unless told not to force.

That is its documented contract, and the reason not to call it at import time: the handlers of an application go with the others.

tests.test_logging.test_new_logger_with_a_name_leaves_the_root_logger_alone(app_handler)[source]ΒΆ

Given a name, new_logger() sets that logger up and no other.

tests.test_logging.application_levels(restored_root_logger)[source]ΒΆ

Give the loggers the levels of an application for the time of a test.

The root logger works at INFO, and the click_extra one follows it, as it does from the start. None of the two is at the level the verbosity options default to: a test can so tell a level given back from one reset.

tests.test_logging.levels()[source]ΒΆ

The levels a verbosity option sets: of root and of click_extra.

tests.test_logging.test_levels_are_given_back_however_the_run_ends(invoke, application_levels, args, exit_code, traced)[source]ΒΆ

A Click Extra command gives its loggers the levels they had before the run back the moment it ends, whatever it ends on.

tests.test_logging.test_logger_of_the_option_gets_its_own_level_back(invoke, application_levels)[source]ΒΆ

An option given a logger of its own leaves the level of root alone, and gives that logger the level it had.

tests.test_logging.test_reset_loggers_falls_back_on_the_default_level(application_levels)[source]ΒΆ

Called with no level to give back, reset_loggers() sets the default one.

tests.test_logging.test_levels_are_given_back_when_a_subcommand_fails_while_parsing(invoke, application_levels)[source]ΒΆ

The context of the group closes, the one of its subcommand never does.

The group carries no verbosity option of its own here: one that does queues the reset on its own context, which closes.

tests.test_logging.test_failed_run_of_a_click_command_gives_its_levels_back_when_collected(invoke, application_levels)[source]ΒΆ

A plain Click command has no hook on a run that fails while parsing: the levels come back once Python collects the context of that run.

tests.test_logging.failing_click_command(contexts, body=None)[source]ΒΆ

A plain Click command that keeps the context of each of its runs alive, and fails while parsing when given an invalid --baskets.

tests.test_logging.test_run_keeps_its_levels_when_a_failed_run_is_collected(invoke, application_levels)[source]ΒΆ

The context of a failed run may be collected in the middle of a later run: the levels are by then the ones of that later run, and stay.

tests.test_logging.test_levels_found_before_a_failed_run_are_the_ones_given_back(invoke, application_levels)[source]ΒΆ

A run that starts on the levels a failed run left behind gives back the ones found before that failed run, not the ones it left.

tests.test_logging.test_released_handler_put_back_on_the_root_logger_prints_nothing(invoke, app_handler, capsys)[source]ΒΆ

Code that saves the handlers of the root logger and puts them back later may attach again a handler its run let go of in between. That handler prints nothing, and the next run takes it off.

A fixture isolating a test does that around a plain Click command that failed while parsing: Python collects the context of that run, and so releases its handler, whenever it sees fit.

tests.test_logging.test_importing_a_cli_leaves_the_root_logger_alone()[source]ΒΆ

In a new interpreter, importing Click Extra and defining a command leave the root logger with the one handler the application gave it.

tests.test_logging.test_root_logger_prints_in_a_new_interpreter_beside_a_named_logger()[source]ΒΆ

A command whose verbosity option sets a named logger still prints the records of the root logger in the style of Click Extra.

Run in a new interpreter: no other command of the process may have given the root logger its handler.

tests.test_logging.test_stream_handler_honors_no_color_from_background_threads(capsys, monkeypatch)[source]ΒΆ

A record emitted with no reachable Click context (as from run_cli’s stream reader threads) still honors –no-color, through the process-wide mirror published by the color options.

tests.test_logging.test_formatter_renders_label_glued_to_level_name()[source]ΒΆ

A record tagged with a label attribute (as run_cli’s streamed output lines are) renders it inside the level prefix: debug:mas: message.

tests.test_logging.test_formatter_starts_a_block_below_its_prefix(label, prefix, message, expected)[source]ΒΆ

A message spanning several lines starts on the line below its prefix, so its first line keeps the columns of the lines under it.

tests.test_logging.test_stream_handler_routes_through_active_spinner(capsys)[source]ΒΆ

A record emitted while a spinner animates on the same stream is printed through Spinner.echo(), on its own line, instead of over the frame.