From 5d91ce18438f4014fa968e0ae909c260e83e0e2c Mon Sep 17 00:00:00 2001 From: Tattoo Date: Thu, 19 Oct 2023 11:58:13 +0300 Subject: [PATCH] fix tests that fail in the pipeline --- .github/workflows/run-tests/action.yml | 1 - src/oxygen/oxygen.py | 16 +++++++++++----- tasks.py | 2 +- tests/utest/zap/test_zap_cli.py | 13 +++++++++++-- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/.github/workflows/run-tests/action.yml b/.github/workflows/run-tests/action.yml index 4c047d5..15606f9 100644 --- a/.github/workflows/run-tests/action.yml +++ b/.github/workflows/run-tests/action.yml @@ -13,7 +13,6 @@ runs: uses: actions/setup-python@v4 with: python-version: ${{ inputs.python-version }} - cache: 'pip' - name: Install dependencies shell: ${{ inputs.terminal }} run: | diff --git a/src/oxygen/oxygen.py b/src/oxygen/oxygen.py index 4f0af4d..36f2dbf 100644 --- a/src/oxygen/oxygen.py +++ b/src/oxygen/oxygen.py @@ -4,6 +4,7 @@ from datetime import datetime, timedelta from inspect import getdoc, signature from io import StringIO +from importlib import import_module from pathlib import Path from shutil import copy as copy_file from traceback import format_exception @@ -50,14 +51,19 @@ def handlers(self): return self._handlers def _register_handlers(self): - for tool_name, config in self.config.items(): + for tool_name, handler_config in self.config.items(): try: - handler_class = getattr(__import__(tool_name, - fromlist=[config['handler']]), - config['handler']) + handler_class = getattr(import_module(tool_name, + handler_config['handler']), + handler_config['handler']) except ModuleNotFoundError as e: raise InvalidConfigurationException(e) - handler = handler_class(config) + except TypeError as e: + print(tool_name) + print(handler_config) + print(self.config) + raise + handler = handler_class(handler_config) self._handlers[tool_name] = handler diff --git a/tasks.py b/tasks.py index 9d47463..0782399 100644 --- a/tasks.py +++ b/tasks.py @@ -38,7 +38,7 @@ def install(context, package=None): 'https://github.com/CleanCut/green/blob/master/cli-options.txt#L5', }) def utest(context, test=None): - run(f'green {" ".join(test) if test else UNIT_TESTS}', + run(f'green {" ".join(test) if test else UNIT_TESTS} -vvv', env={'PYTHONPATH': str(SRCPATH)}, pty=(not system() == 'Windows')) diff --git a/tests/utest/zap/test_zap_cli.py b/tests/utest/zap/test_zap_cli.py index 49db088..cc4d143 100644 --- a/tests/utest/zap/test_zap_cli.py +++ b/tests/utest/zap/test_zap_cli.py @@ -1,9 +1,12 @@ import sys + from unittest import TestCase from unittest.mock import ANY, Mock, create_autospec, patch + from robot.running.model import TestSuite + from oxygen.oxygen import OxygenCLI -from ..helpers import RESOURCES_PATH +from ..helpers import get_config, RESOURCES_PATH class TestOxygenZapCLI(TestCase): @@ -16,6 +19,12 @@ def setUp(self): self.mock = Mock() self.mock.running.build_suite = Mock(return_value=self.expected_suite) + def tearDown(self): + self.cli = None + self.handler = None + self.expected_suite = None + self.mock = None + def test_cli(self): self.assertEqual( self.handler.cli(), @@ -81,7 +90,7 @@ def test_cli_run_with_accepted_risk_level(self, mock_robot_iface): def test_cli_run_with_required_confidence_level(self, mock_robot_iface): mock_robot_iface.return_value = self.mock - cmd_args = f"oxygen oxygen.zap {self.ZAP_XML} " "--required-confidence-level 3" + cmd_args = f"oxygen oxygen.zap {self.ZAP_XML} --required-confidence-level 3" with patch.object(sys, "argv", cmd_args.split()): self.cli.run()