Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Improve error reporting in test case execution #111

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/pykiso/test_coordinator/test_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,10 @@ def execute(

exit_code = failure_and_error_handling(result)
except TestCollectionError:
log.exception("Error occurred during test collections.")
exit_code = ExitCode.ONE_OR_MORE_TESTS_RAISED_UNEXPECTED_EXCEPTION
except AuxiliaryCreationError:
log.exception("Error occurred during auxiliary creation.")
exit_code = ExitCode.AUXILIARY_CREATION_FAILED
except KeyboardInterrupt:
log.exception("Keyboard Interrupt detected")
Expand Down
68 changes: 62 additions & 6 deletions tests/test_config_registry_and_test_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@
# SPDX-License-Identifier: EPL-2.0
##########################################################################

import itertools
import sys
import logging
from unittest import TestCase, TestResult

import pytest

import pykiso
import pykiso.test_coordinator.test_execution
from pykiso import cli
from pykiso.config_parser import parse_config
from pykiso.test_coordinator import test_execution
from pykiso.test_setup.config_registry import ConfigRegistry
Expand All @@ -42,7 +40,9 @@ def test_config_registry_and_test_execution(tmp_test, capsys):
assert "-> Failed" not in output.err


@pytest.mark.parametrize("tmp_test", [("aux1", "aux2", False)], indirect=True)
@pytest.mark.parametrize(
"tmp_test", [("with_pattern_aux1", "_with_pattern_aux2", False)], indirect=True
)
def test_config_registry_and_test_execution_with_pattern(tmp_test, capsys):
"""Call execute function from test_execution using
configuration data coming from parse_config method
Expand All @@ -61,8 +61,12 @@ def test_config_registry_and_test_execution_with_pattern(tmp_test, capsys):
assert "Ran 0 tests" in output.err


@pytest.mark.parametrize("tmp_test", [("aux1", "aux2", False)], indirect=True)
def test_config_registry_and_test_execution_collect_error(tmp_test, capsys, mocker):
@pytest.mark.parametrize(
"tmp_test",
[("collector_error_aux1", "collector_error_aux_2", False)],
indirect=True,
)
def test_config_registry_test_collection_error(tmp_test, capsys, mocker, caplog):
"""Call execute function from test_execution using
configuration data coming from parse_config method
by specifying a pattern
Expand All @@ -87,6 +91,58 @@ def test_config_registry_and_test_execution_collect_error(tmp_test, capsys, mock
assert "Ran 0 tests" not in output.err


@pytest.mark.parametrize(
"tmp_test",
[("collector_error_2_aux1", "collector_error_2_aux", False)],
indirect=True,
)
def test_config_registry_and_test_execution_collect_error(mocker, caplog, tmp_test):
"""Call execute function from test_execution using
configuration data coming from parse_config method
by specifying a pattern

Validation criteria:
- run is executed with test collection error
"""
mocker.patch(
"pykiso.test_coordinator.test_execution.collect_test_suites",
side_effect=pykiso.TestCollectionError("test"),
)

cfg = parse_config(tmp_test)

with caplog.at_level(logging.ERROR):
test_execution.execute(config=cfg)

assert "Error occurred during test collections." in caplog.text


@pytest.mark.parametrize(
"tmp_test", [("creation_error_aux1", "creation_error_aux2", False)], indirect=True
)
def test_config_registry_and_test_execution_test_auxiliary_creation_error(
mocker, caplog, tmp_test
):
"""Call execute function from test_execution using
configuration data coming from parse_config method
by specifying a pattern

Validation criteria:
- run is executed with auxiliary creation error
"""
mocker.patch(
"pykiso.test_coordinator.test_execution.collect_test_suites",
side_effect=pykiso.AuxiliaryCreationError("test"),
)

cfg = parse_config(tmp_test)

with caplog.at_level(logging.ERROR):
test_execution.execute(config=cfg)

assert "Error occurred during auxiliary creation." in caplog.text


@pytest.mark.parametrize("tmp_test", [("text_aux1", "text_aux2", False)], indirect=True)
def test_config_registry_and_test_execution_with_text_reporting(tmp_test, capsys):
"""Call execute function from test_execution using
Expand Down