cli: Fix TTY test failing on Python 3.14

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 a2c68fdf),
but the new one makes more sense to me now.

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=2336947
This commit is contained in:
Adrien Vergé 2025-01-13 17:06:16 +01:00
parent 728656c937
commit e427005b52

View File

@ -499,7 +499,7 @@ class CommandLineTestCase(unittest.TestCase):
# Create a pseudo-TTY and redirect stdout to it # Create a pseudo-TTY and redirect stdout to it
master, slave = pty.openpty() master, slave = pty.openpty()
sys.stdout = sys.stderr = os.fdopen(slave, 'w') sys.stdout = os.fdopen(slave, 'w')
with self.assertRaises(SystemExit) as ctx: with self.assertRaises(SystemExit) as ctx:
cli.run((path, )) cli.run((path, ))
@ -514,7 +514,6 @@ class CommandLineTestCase(unittest.TestCase):
out = output.read().replace('\r\n', '\n') out = output.read().replace('\r\n', '\n')
sys.stdout.close() sys.stdout.close()
sys.stderr.close()
output.close() output.close()
self.assertEqual(out, ( self.assertEqual(out, (