Skip to content

Commit

Permalink
cli: Fix TTY test failing on Python 3.14
Browse files Browse the repository at this point in the history
Since I don't have Python 3.14 on my system (yet), here are the steps I
used to reproduce:

    sudo dnf install python3.14
    python3.14 -m venv /tmp/py3.14
    source /tmp/py3.14/bin/activate
    pip install yaml pathspec
    python3.14 -m unittest discover
    # or
    python3.14 -m unittest tests.test_cli.CommandLineTestCase.test_run_default_format_output_in_tty

This commit fixes that by piping *only* `sys.stdout`, not `sys.stderr`
too. I'm not sure why I wrote this code in 2016 (see commit a2c68fd),
but the new one makes more sense to me now.

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=2336947
  • Loading branch information
adrienverge committed Jan 13, 2025
1 parent 5a3dfb0 commit 4e0a367
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ def test_run_default_format_output_in_tty(self):

# Create a pseudo-TTY and redirect stdout to it
master, slave = pty.openpty()
sys.stdout = sys.stderr = os.fdopen(slave, 'w')
sys.stdout = os.fdopen(slave, 'w')

with self.assertRaises(SystemExit) as ctx:
cli.run((path, ))
Expand All @@ -514,7 +514,6 @@ def test_run_default_format_output_in_tty(self):
out = output.read().replace('\r\n', '\n')

sys.stdout.close()
sys.stderr.close()
output.close()

self.assertEqual(out, (
Expand Down

0 comments on commit 4e0a367

Please sign in to comment.