Skip to content

馃悰 Fix: Ensure rich formatting is preserved in printing tutorial tests - #1974

Closed
Vineshnayak wants to merge 1 commit into
fastapi:masterfrom
Vineshnayak:fix-tutorial-tests
Closed

Vineshnayak wants to merge 1 commit into
fastapi:masterfrom
Vineshnayak:fix-tutorial-tests

Conversation

@Vineshnayak

Copy link
Copy Markdown

Pull Request

Discussion: N/A - Direct fix for failing tests on main branch

Description

This PR fixes two failing tests in the test suite: tests/test_tutorial/test_printing/test_tutorial001.py and test_tutorial002.py.

The Issue:
Currently, these tests fail in some environments because the Console mock strips ANSI escape codes when sys.stdout is intercepted by the CliRunner. When rich.print detects it is not writing to a standard TTY, it defaults the color system to None, causing the normalized output assertions (which look for * placeholders) to fail.

The Fix:
I have explicitly passed color_system="standard" to the mocked Console instances. This forces rich to emit the expected formatting codes regardless of the test environment's stdout redirection.

AI Disclaimer

Prompt:

I want to make a genuine open-source contribution to Typer. Deeply inspect the repo, tests, open issues/PRs, and recent changes to identify a real, reproducible bug or small improvement that isn鈥檛 already being addressed.

Don鈥檛 invent issues or make unnecessary changes. First explain the issue, root cause, reproduction, and proposed minimal fix. Do not modify code yet. Once verified, we鈥檒l implement a clean fix, add regression tests, run the full test suite, and prepare a polished PR following Typer鈥檚 conventions.
Model used: Google Gemini 3.1 Pro

AI transcript

The AI analyzed the Typer repository, executed the pytest suite, and identified that two tutorial printing tests were failing on the master branch due to the Console mock losing formatting. The AI then updated test_tutorial001.py and test_tutorial002.py to instantiate the mocked Console with color_system="standard", successfully restoring the formatting and allowing all tests to pass.

Checklist

  • This PR links to a GitHub Discussion for the proposed code change.
  • I added tests for the change. (N/A: This is a fix for existing tests)
  • The new or updated tests fail on the main branch and pass on this PR.
  • Coverage stays at 100%.
  • The documentation explains the change if needed. (N/A: No docs change needed)

@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

This was marked as potentially AI generated and will be closed now. If this is an error, please provide additional details, make sure to read the docs about contributing and AI.

@github-actions github-actions Bot closed this Oct 6, 2026
@YuriiMotov

Copy link
Copy Markdown
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants