-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Add support for logging in collection-phase #3986
Conversation
src/_pytest/logging.py
Outdated
@@ -425,6 +424,21 @@ def _log_cli_enabled(self): | |||
"--log-cli-level" | |||
) is not None or self._config.getini("log_cli") | |||
|
|||
@pytest.hookimpl(hookwrapper=True) |
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.
Try first could possibly make it more robust
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.
Done. Thx for the suggestion. Probably it makes sense to use tryfirst also for the other hookimpls in the logging plugin, right?
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.
@Thisch quite possible - i never did a formal review of hook orders proceed with caution ^^
src/_pytest/logging.py
Outdated
# so we can access the terminal reporter plugin. | ||
self._setup_cli_logging() | ||
|
||
# TODO write to file support needed? |
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.
@Thisch any reason not to? If there isn't a good reason, I would prefer this to go out feature-complete rather than need another iteration.
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.
Because adding support for log-to-file support is trickier. Simply copying the ctx manager that are used in pytest_runtestloop does not work.
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.
I have a working implementation now. It was necessary to remove the closing
context manager.
The logging plugin does not output log messages generated during the collection-phase when live-logging is enabled. This fixes this. Fixes pytest-dev#3964
Codecov Report
@@ Coverage Diff @@
## features #3986 +/- ##
============================================
+ Coverage 94.5% 94.54% +0.04%
============================================
Files 107 107
Lines 23710 23721 +11
Branches 2353 2357 +4
============================================
+ Hits 22406 22427 +21
+ Misses 993 987 -6
+ Partials 311 307 -4
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## features #3986 +/- ##
============================================
+ Coverage 94.5% 94.54% +0.04%
============================================
Files 107 107
Lines 23710 23734 +24
Branches 2353 2357 +4
============================================
+ Hits 22406 22440 +34
+ Misses 993 987 -6
+ Partials 311 307 -4
Continue to review full report at Codecov.
|
src/_pytest/logging.py
Outdated
|
||
if self.log_file_handler is not None: | ||
with catching_logs(self.log_file_handler, level=self.log_file_level): | ||
yield # run all the tests |
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.
this should be # perform collection
😁
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.
I'll simply remove this comment.
self.log_file_handler, level=self.log_file_level | ||
): | ||
yield # run all the tests | ||
with catching_logs(self.log_file_handler, level=self.log_file_level): |
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.
So in the end is not really necessary to close log_file_handler
explicitly?
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.
No, it is not necessary. An alternative to removing the closing ctx manager would be to create the log_file_handler object twice.
Great, thanks a lot for the work @Thisch! As far as I'm concerned this can be merged when CI passes. 👍 |
The logging plugin does not output log messages generated during the
collection-phase when live-logging is enabled. This fixes this.
Fixes #3964