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

Fix ANSI escape codes for colored output not handled correctly with pytest.fail(..., pytrace=False) #12959

Conversation

leonarduschen
Copy link
Contributor

@leonarduschen leonarduschen commented Nov 13, 2024

Closes #12849


Description:


  • Include documentation when adding new features.
  • Include new tests or update existing tests when applicable.
  • Allow maintainers to push and squash when merging my commits. Please uncheck this if you prefer to squash the commits yourself.
  • Add text like closes #XYZW to the PR description and/or commits (where XYZW is the issue number). See the github docs for more information.
  • Create a new changelog file in the changelog folder, with a name like <ISSUE NUMBER>.<TYPE>.rst. See changelog/README.rst for details.
  • Add yourself to AUTHORS in alphabetical order.

@leonarduschen leonarduschen marked this pull request as draft November 13, 2024 17:34
@psf-chronographer psf-chronographer bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Nov 14, 2024
@leonarduschen leonarduschen changed the title Fix ExcInfo.value printed as source code Fix ANSI escape codes for colored output not handled correctly with pytest.fail(..., pytrace=False) Nov 14, 2024
@leonarduschen leonarduschen marked this pull request as ready for review November 14, 2024 16:32
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.

LGTM, thanks for the PR, appreciate it!

src/_pytest/_code/code.py Show resolved Hide resolved
testing/conftest.py Show resolved Hide resolved
@nicoddemus nicoddemus added the backport 8.3.x apply to PRs at any point; backports the changes to the 8.3.x branch label Nov 21, 2024
@nicoddemus
Copy link
Member

Thanks @leonarduschen!

Will squash/merge in a few days to give others a chance to review it. 👍

@leonarduschen
Copy link
Contributor Author

Sure thing @nicoddemus, thanks for the review! Excited for my first contribution :)

@nicoddemus nicoddemus merged commit 76e0444 into pytest-dev:main Nov 25, 2024
29 checks passed
Copy link

patchback bot commented Nov 25, 2024

Backport to 8.3.x: 💚 backport PR created

✅ Backport PR branch: patchback/backports/8.3.x/76e044477010dcc0e31d4a736b7130e044a01a7e/pr-12959

Backported as #12990

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

patchback bot pushed a commit that referenced this pull request Nov 25, 2024
- When `ReprEntry.style == "value"` (happens when calling `pytest.fail(..., pytrace=False)`, the message should not be printed to terminal using `TerminalWriter._write_source` because then it'll try to highlight the message as source code
- The message should be printed to terminal directly using `TerminalWriter.line` or `TerminalWriter.write`, I went with the later for testing purposes #12959 (comment)

Closes #12849

(cherry picked from commit 76e0444)
nicoddemus pushed a commit that referenced this pull request Nov 25, 2024
- When `ReprEntry.style == "value"` (happens when calling `pytest.fail(..., pytrace=False)`, the message should not be printed to terminal using `TerminalWriter._write_source` because then it'll try to highlight the message as source code
- The message should be printed to terminal directly using `TerminalWriter.line` or `TerminalWriter.write`, I went with the later for testing purposes #12959 (comment)

Closes #12849

(cherry picked from commit 76e0444)

Co-authored-by: Leonardus Chen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 8.3.x apply to PRs at any point; backports the changes to the 8.3.x branch bot:chronographer:provided (automation) changelog entry is part of PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ANSI escape codes for colored output not handled correctly with pytest.fail(reason=..., pytrace=False)
2 participants