-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Making --debug
more configurable for the pytest user
#8955
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
Conversation
--debug
more configurable for the pytest user
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.
Looks good, thanks! Left a few comments, please take a look.
src/_pytest/helpconfig.py
Outdated
metavar="DEBUG_FILE_NAME", | ||
help="store internal tracing debug information in this log file.\n" | ||
"This file is opened with 'w' and truncated as a result, care advised.\n" | ||
"Defaults to 'pytestdebug.log', '.log' is suffixed if omitted.", |
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.
"Defaults to 'pytestdebug.log', '.log' is suffixed if omitted.", | |
"Defaults to 'pytestdebug.log', '.log' is suffixed if omitted.", |
I think we don't need to automatically append .log
if omitted... I the user passes a file, let's just use that instead of trying to be helpful here.
src/_pytest/helpconfig.py
Outdated
config.trace.root.setwriter(None) | ||
undo_tracing() | ||
|
||
config.add_cleanup(unset_tracing) | ||
|
||
|
||
def _resolve_debug_log_name(file_name: str) -> str: |
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 I mentioned, I don't think we need this.
testing/test_config.py
Outdated
@@ -2042,3 +2043,58 @@ def test_parse_warning_filter_failure(arg: str) -> None: | |||
|
|||
with pytest.raises(warnings._OptionError): | |||
parse_warning_filter(arg, escape=True) | |||
|
|||
|
|||
def test_debug_file_name_is_suffixed_with_dot_log() -> None: |
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.
Personally I would group those new tests into a class:
class TestDebugOption:
def test_suffixed_with_dot_log() -> None:
...
But that's just a matter of choice I guess.
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.
Good work, thanks @symonk!
Thanks again @nicoddemus for the review, should be sorted now, appreciate it. |
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.
Thanks!
Hi all, hope you are well,
This patch adds capabilities to provide a customised file name to
--debug
which routes the debug logs into a file of the users choice. I have proposed this because we use multiple pytest executions as part of one jenkins job and find we have a wealth of internal plugins, running each run with--debug
and artifacting the log is useful for us on a per run basis, we run parallel tests with xdist (want the debug log) then isolated sequential tests in a single process (want the debug log) and by default, this overwrites the pytestdebug.log. see #8954 for some of my reasoning.This remains the same functionality to most users in the sense that:
There are now 3 options to
--debug
:--debug
in isolation will result in apytestdebug.log
file in the root directory as prior--debug
omitted from the command line (ini args etc) will result in no log file written--debug mylog
will result inmylog.log
holding the debug logsNotes:
.log
is suffixed to the user file if it does not end in.log
just to keep things relatively similar to the original file herew
, so there is a chance someone passes a file that exists and we truncate and write logs to it 🤔 (not really sure how to solve that one, we don't want to append and can't check if it exists do nothing as overwriting it is the norm)Let me know what you think, thanks!
Close #8954