Skip to content

Commit

Permalink
feat: Improve error reporting in test case execution
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien THOMAS committed Aug 3, 2022
1 parent 3d7b683 commit 2700f2c
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/pykiso/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
.. currentmodule:: exceptions
"""
import logging


class PykisoError(Exception):
"""Pykiso specific exception used as basis for all others."""

def __str__(self):
logging.exception(self.message)
return self.message


Expand Down
5 changes: 4 additions & 1 deletion src/pykiso/test_coordinator/test_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,9 @@ def execute(
log.exception("Keyboard Interrupt detected")
exit_code = ExitCode.ONE_OR_MORE_TESTS_RAISED_UNEXPECTED_EXCEPTION
except Exception:
log.exception(f'Issue detected in the test-suite: {config["test_suite_list"]}!')
log.exception(
f"Following exception : {type(Exception)} occurred"
f' in the test-suite: {config["test_suite_list"]}!'
)
exit_code = ExitCode.ONE_OR_MORE_TESTS_RAISED_UNEXPECTED_EXCEPTION
return int(exit_code)
72 changes: 70 additions & 2 deletions tests/test_config_registry_and_test_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
##########################################################################

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

Expand Down Expand Up @@ -62,7 +63,9 @@ def test_config_registry_and_test_execution_with_pattern(tmp_test, capsys):


@pytest.mark.parametrize("tmp_test", [("aux1", "aux2", False)], indirect=True)
def test_config_registry_and_test_execution_collect_error(tmp_test, capsys, mocker):
def test_config_registry_and_test_execution_collect_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 @@ -78,7 +81,72 @@ def test_config_registry_and_test_execution_collect_error(tmp_test, capsys, mock
ConfigRegistry.register_aux_con(cfg)

with pytest.raises(pykiso.TestCollectionError):
test_execution.collect_test_suites(cfg["test_suite_list"])
with caplog.at_level(logging.ERROR):
test_execution.collect_test_suites(cfg["test_suite_list"])

assert "Failed to collect test suite" in caplog.text

ConfigRegistry.delete_aux_con()

output = capsys.readouterr()
assert "FAIL" not in output.err
assert "Ran 0 tests" not in output.err


@pytest.mark.parametrize("tmp_test", [("aux1", "aux2", False)], indirect=True)
def test_config_registry_and_test_execution__auxiliary_creation_error(
tmp_test, capsys, mocker, caplog
):
"""Call execute function from test_execution using
configuration data coming from parse_config method
by specifying a pattern
Validation criteria:
- run is executed without error
"""
mocker.patch(
"pykiso.test_coordinator.test_suite.tc_sort_key", side_effect=Exception
)

cfg = parse_config(tmp_test)
ConfigRegistry.register_aux_con(cfg)

with pytest.raises(pykiso.AuxiliaryCreationError):
with caplog.at_level(logging.ERROR):
test_execution.collect_test_suites(cfg["test_suite_list"])

assert "failed at instance creation" in caplog.text

ConfigRegistry.delete_aux_con()

output = capsys.readouterr()
assert "FAIL" not in output.err
assert "Ran 0 tests" not in output.err


@pytest.mark.parametrize("tmp_test", [("aux1", "aux2", False)], indirect=True)
def test_config_registry_and_test_execution__auxiliary_creation_error(
tmp_test, capsys, mocker, caplog
):
"""Call execute function from test_execution using
configuration data coming from parse_config method
by specifying a pattern
Validation criteria:
- run is executed without error
"""
mocker.patch(
"pykiso.test_coordinator.test_suite.tc_sort_key", side_effect=Exception
)

cfg = parse_config(tmp_test)
ConfigRegistry.register_aux_con(cfg)

with pytest.raises(Exception):
with caplog.at_level(logging.ERROR):
test_execution.collect_test_suites(cfg["test_suite_list"])

assert "Following exception" in caplog.text

ConfigRegistry.delete_aux_con()

Expand Down

0 comments on commit 2700f2c

Please sign in to comment.