Skip to content

Commit

Permalink
Use get if PYTHONUNBUFFERED is not defined`
Browse files Browse the repository at this point in the history
  • Loading branch information
WolframAlph committed Dec 31, 2024
1 parent 565f15c commit 7ff7de3
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions Lib/test/test_cmd_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,13 @@ def test_osx_android_utf8(self):
self.assertEqual(p.returncode, 0)

def test_non_interactive_output_buffering(self):
PYTHONUNBUFFERED_ENV_VAR = os.environ["PYTHONUNBUFFERED"]
# we expect buffered stdio
os.environ["PYTHONUNBUFFERED"] = "0"
PYTHONUNBUFFERED = "PYTHONUNBUFFERED"
python_unbuffered_value = os.environ.get(PYTHONUNBUFFERED, "0")
python_unbuffered_on = python_unbuffered_value != "0"
if python_unbuffered_on:
# we expect buffered stdio
os.environ[PYTHONUNBUFFERED] = "0"

code = textwrap.dedent("""
import sys
out = sys.stdout
Expand All @@ -353,8 +357,10 @@ def test_non_interactive_output_buffering(self):
self.assertEqual(proc.stdout,
'False False False\n'
'False False True\n')
# restore original value
os.environ["PYTHONUNBUFFERED"] = PYTHONUNBUFFERED_ENV_VAR

if python_unbuffered_on:
# restore original value
os.environ[PYTHONUNBUFFERED] = python_unbuffered_value

def test_unbuffered_output(self):
# Test expected operation of the '-u' switch
Expand Down

0 comments on commit 7ff7de3

Please sign in to comment.