Skip to content

Add Tier-A logging/verbosity tests; rename logger; fix JSON encoder bug#2

Merged
wangxin merged 1 commit into
mainfrom
logging-verbosity-tests
Jun 11, 2026
Merged

Add Tier-A logging/verbosity tests; rename logger; fix JSON encoder bug#2
wangxin merged 1 commit into
mainfrom
logging-verbosity-tests

Conversation

@wangxin

@wangxin wangxin commented Jun 11, 2026

Copy link
Copy Markdown
Owner

Summary

Add 4 tests covering the verbosity/logging behavior, rename the logger and env var to match the package name, and fix a TypeError in the verbosity logging path that the new tests surfaced.

Renames

  • Logger: ansible_pyapiansible_host
  • Env var: ANSIBLE_PYAPI_VERBOSITYANSIBLE_HOST_VERBOSITY

Both names were stale from before the package was renamed.

Bug fix

json.dumps() in the verbosity logging path crashed with TypeError: Object of type Task is not JSON serializable on ansible-core 2.19+ — same family as the earlier _check_failed_results fix. Hit four call sites in _run() (v=2 task fields, v=2/3 results, v=4 stats). All now use default=str.

The bug was invisible until now because it only triggers when a DEBUG handler is attached to the ansible_host logger at default-or-higher verbosity — exactly the path users hit when trying to debug a problem.

Tests

Test Pins down
test_display_verbosity_is_restored_after_run display.verbosity save/restore — guards against silent stomp of global Ansible state
test_default_verbosity_emits_compact_json Default v=2 emits the per-task action + args/kwargs/directives line
test_verbosity_zero_emits_no_library_logs v=0 silences all library output
test_options_verbosity_overrides_env_var options['verbosity'] wins over ANSIBLE_HOST_VERBOSITY; v=3 emits indented JSON

Validation

37 tests pass locally (3 smoke + 30 tier-1 + 4 tier-A), ruff clean.

- Rename logger 'ansible_pyapi' -> 'ansible_host' and env var
  ANSIBLE_PYAPI_VERBOSITY -> ANSIBLE_HOST_VERBOSITY so both match the
  package name. Stale 'pyapi' names predated the rename.

- Fix a TypeError in the verbosity logging path: json.dumps in the
  v=2 task-fields log and the v=2/3/4 results/stats logs crashed on
  non-serializable Task instances on ansible-core 2.19+. Added
  default=str to all four call sites. Same family as the earlier
  _check_failed_results fix; was hidden because the bug only triggers
  when a DEBUG handler is attached to the ansible_host logger.

- Add 4 Tier-A tests in test_logging_and_verbosity.py:
  - display.verbosity is restored after _run (regression guard)
  - default verbosity emits the compact v=2 task line
  - options={'verbosity': 0} silences all library logs
  - options['verbosity'] overrides ANSIBLE_HOST_VERBOSITY env var

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Xin Wang <wangxin.wang@gmail.com>
@wangxin
wangxin merged commit 69d72d1 into main Jun 11, 2026
17 checks passed
@wangxin
wangxin deleted the logging-verbosity-tests branch June 11, 2026 06:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant