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

Dedicated caplog recording handler #24

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

abusalimov
Copy link
Collaborator

Changes affecting users:

  • Now caplog.text always uses the same formatting, regardless the --log-format option. You won't want your tests fail because the user prefers another formatting, after all
  • Changing the logging level through caplog does not affect captured logs shown in case of a failure (this is still not the case when using caplog.at_level/set_level(logger=...) though, but I'm going to address this one too in future)

Note: This contains changes that you might happen to review as part of #7, I decided to drop these changes from there eventually.

This makes a distinction between two features / use cases:

  1. Inspection: record and check logs emitted by the code being tested
     using the `caplog` fixture

  2. Reporting: show all logs in case of a failure

Implemented through adding a dedicated log handler for the recording.
As a bonus, simplifies the capturing logic (no more awkward
item.catch_log_handler).

Also move LogCaptureHandler into fixture.py.
We don't need a list of records provided by CatchLogHandler for the
reporting facility. So, storing of the records is now only performed
for the `caplog` fixture inspecting purposes.

Also rename 'CatchLogHandler' to 'RecordingHandler', which in turn,
is also turned into a new-style class that uses super() where
appropriate.
In case when a log record has mutable objects attached as arguments,
the getMessage() method may return different results each time it is
called. Instead, use the 'message' field initialized by a formatter
upon a record reaches a handler.
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