diff --git a/tests.py b/tests.py
index 5336a1f6d276356abee16e4311f717369157f7f3..dee5f370a123535a418ab54ec582984451672762 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()