Skip to content
Snippets Groups Projects

test that the counter works

Merged Ashwin Kumar Karnad requested to merge complete-tests-for-run into main
1 file
+ 2
1
Compare changes
  • Side-by-side
  • Inline
  • ac7d45a0
    minor modification · ac7d45a0
    Hans Fangohr authored
    - 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.
+ 2
1
@@ -102,10 +102,11 @@ def test_run_method(tmp_path):
@@ -102,10 +102,11 @@ def test_run_method(tmp_path):
# check that ##-08 is printed when run(["echo", "Good Bye, world!"]) is run
# check that ##-08 is printed when run(["echo", "Good Bye, world!"]) is run
# the 8 in ##-08 is present because
# the 8 in ##-08 is present because
# this is the 8th run of the `run` function
# 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.
captured_output = StringIO() # create an in-memory file-like object.
sys.stdout = captured_output # redirect stdout to the file
sys.stdout = captured_output # redirect stdout to the file
run(["echo", "Good Bye, world!"])
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()
assert "##-08" in captured_output.getvalue()
Loading