From ac7d45a0c8fbe029d86ac47533b077c537014aad Mon Sep 17 00:00:00 2001
From: Hans Fangohr <fangohr@mpsd-ssu-linux-hf.desy.de>
Date: Thu, 1 Jun 2023 17:10:47 +0200
Subject: [PATCH] minor modification

- sys.__stdout__ is the value stdout had at the beginning of the Python program.
- instead, let's reconnect to the stdout stream we used immediately before we
  redirected into the StringIO object. This should be (mildly) more robust.
---
 tests.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tests.py b/tests.py
index 5336a1f..dee5f37 100644
--- a/tests.py
+++ b/tests.py
@@ -102,10 +102,11 @@ def test_run_method(tmp_path):
     # check that ##-08 is printed when run(["echo", "Good Bye, world!"]) is run
     # the 8 in ##-08 is present because
     # this is the 8th run of the `run` function
+    stdout_original = sys.stdout  # preserve current stdout stream
     captured_output = StringIO()  # create an in-memory file-like object.
     sys.stdout = captured_output  # redirect stdout to the file
     run(["echo", "Good Bye, world!"])
-    sys.stdout = sys.__stdout__  #  restores the original stdout
+    sys.stdout = stdout_original  #  restores the original stdout
     assert "##-08" in captured_output.getvalue()
 
 
-- 
GitLab