From aca4c1ac2252c4eb49f5cdf57f8fa84198bcf239 Mon Sep 17 00:00:00 2001
From: Markus Ostermayer <markus.ostermayer@student.tugraz.at>
Date: Thu, 27 Oct 2022 00:26:54 +0200
Subject: [PATCH] added argument to choose if colored output gets used

---
 swet/_main.py      | 15 +++++++++++++++
 swet/_testutils.py |  6 +++++-
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/swet/_main.py b/swet/_main.py
index bf9303a..c5f9785 100644
--- a/swet/_main.py
+++ b/swet/_main.py
@@ -22,6 +22,20 @@ def main(argv: Sequence[str] | None = None) -> int:
         help='Displays all available tests the tester could fined',
     )
 
+    parser.add_argument(
+        '--no-use-colors',
+        dest='use_colors',
+        action='store_false',
+        help='Disable colorful output when running tests',
+    )
+
+    parser.add_argument(
+        '--use-colors',
+        dest='use_colors',
+        action='store_true',
+        help='Uses colorful output when running tests',
+    )
+
     parser.add_argument(
         '--run-tests',
         dest='run_tests',
@@ -83,6 +97,7 @@ def main(argv: Sequence[str] | None = None) -> int:
     return_val = _run_tests(
         tests_to_run,
         args.build_path,
+        args.use_colors,
         args.testreport,
     )
 
diff --git a/swet/_testutils.py b/swet/_testutils.py
index 2065a3f..bc23210 100644
--- a/swet/_testutils.py
+++ b/swet/_testutils.py
@@ -109,6 +109,7 @@ def execute_test(
     testname: TestFile,
     build_path: str,
     code_path: str,
+    use_colors: bool,
     testreport: bool = False,
 ) -> int:
 
@@ -138,7 +139,7 @@ def execute_test(
     with open(
         f'{build_path}/{testname.filename_without_ending}.log',
     ) as logfile:
-        for logline in follow(logfile, use_color=True):
+        for logline in follow(logfile, use_color=use_colors):
             if 'Assertion failed' in logline:
                 test_result = Result.failed
 
@@ -150,6 +151,7 @@ def execute_test(
     _print_testresult(
         testname.filename_without_ending.ljust(30, '.'),
         test_status=test_result,
+        use_colors=use_colors,
     )
 
     if test_result == Result.failed:
@@ -161,6 +163,7 @@ def execute_test(
 def _run_tests(
     tests_to_run: list[TestFile],
     build_path: str,
+    use_colors: bool,
     testreport: bool,
 ) -> int:
 
@@ -233,6 +236,7 @@ def _run_tests(
             test,
             build_path,
             code_path,
+            use_colors,
         )
         ret_val |= exec_test_ret_val
 
-- 
GitLab