From 9d62ea27b74d3b6367082f2c3b8ad1c2f697fc72 Mon Sep 17 00:00:00 2001 From: iamashwin99 <ashwin-kumar.karnad@mpsd.mpg.de> Date: Wed, 31 May 2023 14:18:43 +0200 Subject: [PATCH] test that the counter works --- tests.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests.py b/tests.py index 43d08a7..5336a1f 100644 --- a/tests.py +++ b/tests.py @@ -5,6 +5,8 @@ import os import shutil import subprocess from pathlib import Path +from io import StringIO +import sys import pytest @@ -96,6 +98,16 @@ def test_run_method(tmp_path): with pytest.raises(subprocess.CalledProcessError): run(["ls", "/doesnotexist"], check=True) + # test that the counter works correctly: + # 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 + 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 + assert "##-08" in captured_output.getvalue() + def test_prepare_environment(tmp_path): """Simulate running preparation of environment. -- GitLab