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 9d5b462
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/pykiso/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
.. currentmodule:: exceptions
"""
import logging


class PykisoError(Exception):
Expand Down
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
67 changes: 64 additions & 3 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 @@ -42,7 +43,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 +64,14 @@ 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_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 @@ -87,6 +96,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_2(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 without 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 without 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

0 comments on commit 9d5b462

Please sign in to comment.