Skip to content

Commit

Permalink
add cli execution time
Browse files Browse the repository at this point in the history
  • Loading branch information
Sispheor committed Nov 29, 2022
1 parent a44d9fd commit 837b1f3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
12 changes: 9 additions & 3 deletions monkeyble/cli/monkeyble_cli.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import argparse
import logging
import os
import pathlib
import subprocess
import sys
import pathlib
import time
from datetime import datetime, timedelta

import yaml
from tabulate import tabulate

Expand Down Expand Up @@ -95,7 +98,7 @@ def print_result_table(monkeyble_results):
print(tabulate(table, headers=headers, tablefmt="presto"))


def do_exit(test_results):
def do_exit(test_results, start_time):
"""
Exit with code 1 if at least one test has failed
"""
Expand All @@ -110,6 +113,8 @@ def do_exit(test_results):
else:
at_least_one_test_failed = True
print("")
end_time = time.monotonic()
Utils.print_info(f"⏱ Monkeyble execution time: {timedelta(seconds=end_time - start_time)}")
test_result_message = f"Tests passed: {total_passed} of {total_test} tests"
if at_least_one_test_failed:
Utils.print_danger(f"🙊 Monkeyble test result - {test_result_message}")
Expand Down Expand Up @@ -177,9 +182,10 @@ def main():
config = load_monkeyble_config(parser.config)

if parser.action == "test":
start_time = time.monotonic()
test_results = run_monkeyble_test(config)
print_result_table(test_results)
do_exit(test_results)
do_exit(test_results, start_time)


if __name__ == '__main__':
Expand Down
5 changes: 3 additions & 2 deletions tests/units/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import io
import os
import pathlib
import time
import unittest
from unittest import mock
from unittest.mock import patch, mock_open, call
Expand Down Expand Up @@ -51,7 +52,7 @@ def test_do_exit_all_test_passed(self, mock_exit):
scenario_result2 = ScenarioResult(scenario="scenario2", result=TEST_PASSED)
monkeyble_result = MonkeybleResult(playbook="playbook", scenario_results=[scenario_result1, scenario_result2])

do_exit([monkeyble_result])
do_exit([monkeyble_result], time.monotonic())
mock_exit.assert_called_with(0)

@patch('sys.exit')
Expand All @@ -60,7 +61,7 @@ def test_do_exit_all_test_failed(self, mock_exit):
scenario_result2 = ScenarioResult(scenario="scenario2", result=TEST_FAILED)
monkeyble_result = MonkeybleResult(playbook="playbook", scenario_results=[scenario_result1, scenario_result2])

do_exit([monkeyble_result])
do_exit([monkeyble_result], time.monotonic())
mock_exit.assert_called_with(1)

@patch('sys.exit')
Expand Down

0 comments on commit 837b1f3

Please sign in to comment.