-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Expose log_cli
as a CLI parser option.
#3190
Conversation
Is it worth the hassle to automatically enable logs streaming if |
e34bf2a
to
fb58033
Compare
fb58033
to
be2b10b
Compare
are you aware that |
Yes, I am aware and for this particular feature I think its worth the extra CLI arg. If its desirable not to be added and the auto enable feature is accepted, I'm OK dropping it because in the end my worflow is guaranteed. Just tell me what's desired. |
_pytest/logging.py
Outdated
'log_cli', default=False, type='bool', | ||
help='enable log display during test run (also known as "live logging").') | ||
add_option_ini( | ||
'--log-stream', |
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.
Why did you invent a new name? Why not --log-cli?
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.
Seems weird, --log-cli
, and --log-stream
just seemed more explicative. I have no issues making it --log-cli
though...
_pytest/logging.py
Outdated
auto_enable_log_stream = self._config.getoption('--log-cli-level') | ||
if auto_enable_log_stream is not None: | ||
# Explicitely enable log_cli is --log-cli-level was passed on the CLI | ||
# It won't be automatically enabled is set on the ini file. |
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.
@nicoddemus Are you aware of similar code (where command line options set sth automatically but not ini options) within other parts of pytest?
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.
The reason why it's only enabled automatically for the CLI option and not the INI option is because of the concerns raised on my initial PR.
Also, this PR automatically set's verbosity to 1 if log_cli
is 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.
I'm more concerned that automatically enabling live-logs if log-cli-level is set conflicts with a valid use case (IMHO): user sets log_cli_level=DEBUG
on pytest.ini
so that they can just pass -o log_cli=true
on the command-line and see DEBUG log messages live.
But to be honest I never used live logging, so I'm not sure even if this is an important/valid use case, so I will defer to @Thisch the final verdict on this. 👍
2dd23fe
to
244096d
Compare
@nicoddemus we only automatically enable live logs if use passes |
OH right thanks for pointing that out, my bad. Then I think it makes perfectly sense for In this case can we drop the |
Sure, I'll update in a couple of hours. |
_pytest/logging.py
Outdated
if auto_enable_log_stream is not None: | ||
# Explicitely enable log_cli is --log-cli-level was passed on the CLI | ||
# It won't be automatically enabled is set on the ini file. | ||
config._inicache['log_cli'] = config._parser._inidict['log_cli'] = 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.
I don't think we should be changing the config._*
attributes, I prefer we isolate this predicate into a method and use that instead, for example:
def _stream_logs(self):
return self._config.getoption('--log-cli-level') is not None or self._config.getini('log_cli')
changelog/3190.feature
Outdated
@@ -0,0 +1,2 @@ | |||
Expose `log_cli` as a CLI parser option. |
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.
As commented, let's drop this, and we can make this description more concise:
Passing `--log-cli-level` in the command-line now automatically activates live logging.
result.stdout.fnmatch_lines([ | ||
'*test_log_cli_auto_enable*100%*', | ||
'=* 1 passed in *=', | ||
]) |
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.
Please also ensure that no logging message is shown:
assert 'INFO' not in result.stdout.str()
assert 'WARNING' not in result.stdout.str()
Great, thanks, we appreciate it! 👍 |
0c5b2dd
to
421a764
Compare
Should be ready for another review. |
421a764
to
0b71255
Compare
Thanks @s0undt3ch! I took the liberty of renaming |
Sure, no problem! |
_pytest/logging.py
Outdated
or because --log-cli-level was given in the command-line. | ||
""" | ||
return self._config.getoption('--log-cli-level') is not None or \ | ||
self._config.getini('log_cli') |
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.
Thx for introducing a method for this! This improves the readability IMO.
Thanks for submitting a PR, your contribution is really appreciated!
Here's a quick checklist that should be present in PRs:
$issue_id.$type
for example (588.bugfix)removal
,feature
,bugfix
,vendor
,doc
ortrivial
bugfix
,vendor
,doc
ortrivial
fixes, targetmaster
; for removals or features targetfeatures
;Unless your change is a trivial or a documentation fix (e.g., a typo or reword of a small section) please:
AUTHORS
, in alphabetical order;