Skip to content

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

Merged
merged 4 commits into from
Jul 30, 2021

Conversation

symonk
Copy link
Member

@symonk symonk commented Jul 29, 2021

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 a pytestdebug.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 in mylog.log holding the debug logs

Notes:

  • .log is suffixed to the user file if it does not end in .log just to keep things relatively similar to the original file here
  • unit / integration tests added
  • caveat: This is now user input and we open with w, 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

@symonk symonk changed the title Add debug file Making --debug more configurable for the pytest user Jul 29, 2021
Copy link
Member

@nicoddemus nicoddemus left a 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.

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.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"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.

config.trace.root.setwriter(None)
undo_tracing()

config.add_cleanup(unset_tracing)


def _resolve_debug_log_name(file_name: str) -> str:
Copy link
Member

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.

@@ -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:
Copy link
Member

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.

Copy link
Member

@nicoddemus nicoddemus left a 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!

@symonk
Copy link
Member Author

symonk commented Jul 30, 2021

Good work, thanks @symonk!

Thanks again @nicoddemus for the review, should be sorted now, appreciate it.

Copy link
Member

@nicoddemus nicoddemus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@nicoddemus nicoddemus merged commit d5c62d0 into pytest-dev:main Jul 30, 2021
RonnyPfannschmidt pushed a commit to RonnyPfannschmidt/pytest that referenced this pull request Oct 1, 2021
@symonk symonk deleted the add-debug-file branch October 14, 2021 12:02
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.

make --debug more configurable via --debug-file or --debug-append
2 participants