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

Implement CLI options to set truncation thresholds #12766

Merged
merged 33 commits into from
Sep 21, 2024

Conversation

zhukoff-pavel
Copy link
Contributor

@zhukoff-pavel zhukoff-pavel commented Sep 2, 2024

closes #12765

Example implementation of truncation limit setting with CLI flags

@psf-chronographer psf-chronographer bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Sep 2, 2024
@zhukoff-pavel zhukoff-pavel marked this pull request as ready for review September 2, 2024 18:48
@nicoddemus
Copy link
Member

Thanks @zhukoff-pavel, we appreciate the PR!

I would like to see what other maintainers think of this feature, overall I'm +1 on it, the only downside I see is the cognitive load of extra options... but perhaps others have different opinions here.

I also wonder if this is better implemented as an ini option instead... seems like it would be more common to set this in the config file in test suites where this feature is often wanted (and of course it is always pass this using the -o option in the command line).

@zhukoff-pavel
Copy link
Contributor Author

@nicoddemus, thank you for your reply!

I also wonder if this is better implemented as an ini option instead... seems like it would be more common to set this in the config file in test suites where this feature is often wanted (and of course it is always pass this using the -o option in the command line).

Maybe it is better to implement an .ini option and CLI flag to e.g. temporarily override limits in a singular launch?

Is it possible to implement such behaviour with current option reading machinery (with some combination of addoption and addini methods)?

@nicoddemus
Copy link
Member

nicoddemus commented Sep 9, 2024

Maybe it is better to implement an .ini option and CLI flag to e.g. temporarily override limits in a singular launch?

Your suggestion makes sense, however we have for awhile moved away from this because:

  1. It involves a lot of code duplication
  2. We have mechanisms today where users can use them interchangeably (use addopts to hard-code command-line options in the ini file, and use -o to pass config options in the command line).

For this reason nowadays we prefer to have either a command-line option (for features where users are likely to change between pytest invocations) or an ini option (where users are most likely to set once per repository).

Is it possible to implement such behaviour with current option reading machinery (with some combination of addoption and addini methods)?

Unfortunately no, it requires duplicating the code.

@zhukoff-pavel
Copy link
Contributor Author

zhukoff-pavel commented Sep 9, 2024

I see.
I can then rewrite this PR to implement .ini option instead, as it definitely looks more like a one-time config setting rather than per launch.

Thank you for a quick reply!

@nicoddemus
Copy link
Member

I can then rewrite this PR to implement .ini option instead

Thanks! I suggest to wait a bit in case some other maintainer has comments or reservations about the feature though.

@nicoddemus
Copy link
Member

Been awhile and nobody seems to be against the idea, so feel free to go ahead.

@zhukoff-pavel zhukoff-pavel marked this pull request as draft September 16, 2024 16:39
@zhukoff-pavel zhukoff-pavel marked this pull request as ready for review September 16, 2024 16:51
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 @zhukoff-pavel!

Please take a look at my comments.

changelog/12765.feature.rst Outdated Show resolved Hide resolved
doc/en/how-to/output.rst Outdated Show resolved Hide resolved
src/_pytest/assertion/truncate.py Outdated Show resolved Hide resolved
testing/test_assertion.py Outdated Show resolved Hide resolved
@zhukoff-pavel zhukoff-pavel marked this pull request as draft September 16, 2024 20:11
@zhukoff-pavel zhukoff-pavel marked this pull request as ready for review September 16, 2024 21:14
@zhukoff-pavel
Copy link
Contributor Author

@nicoddemus , thank you for a thorough review!

Please have a look at the changes.

I implemented some logic regarding value of 0 being set in one mode or both at a time.

src/_pytest/assertion/truncate.py Outdated Show resolved Hide resolved
doc/en/how-to/output.rst Show resolved Hide resolved
changelog/12765.feature.rst Show resolved Hide resolved
doc/en/how-to/output.rst Show resolved Hide resolved
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 @zhukoff-pavel!

Two minor things still missing, but after that it LGTM! 😁

Thanks for the patience.

doc/en/how-to/output.rst Show resolved Hide resolved
src/_pytest/assertion/truncate.py Outdated Show resolved Hide resolved
@zhukoff-pavel
Copy link
Contributor Author

@nicoddemus, thank you for review and ideas!

doc/en/reference/reference.rst Outdated Show resolved Hide resolved
doc/en/reference/reference.rst Outdated Show resolved Hide resolved
doc/en/reference/reference.rst Outdated Show resolved Hide resolved
doc/en/reference/reference.rst Outdated Show resolved Hide resolved
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 a lot @zhukoff-pavel, appreciate the patience! 👍

Leaving this open for awhile in case anybody else wants to review it, otherwise I will merge it soon.

@nicoddemus nicoddemus merged commit d924a63 into pytest-dev:main Sep 21, 2024
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot:chronographer:provided (automation) changelog entry is part of PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Customisable truncation limits
2 participants