Skip to content

Commit

Permalink
Added test for report reloader.
Browse files Browse the repository at this point in the history
  • Loading branch information
M6AI committed Aug 15, 2023
1 parent ae008c7 commit 1b3e577
Showing 1 changed file with 60 additions and 5 deletions.
65 changes: 60 additions & 5 deletions tests/unit/testplan/runnable/interactive/test_irunner.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test the interactive test runner."""
from copy import deepcopy
from unittest import mock

import pytest
Expand All @@ -14,6 +15,7 @@
from testplan.testing.multitest import driver
from testplan.runnable.interactive import base
from testplan.common.utils.path import default_runpath
from testplan.common.utils.testing import check_report
from testplan.runners.local import LocalRunner


Expand Down Expand Up @@ -142,8 +144,6 @@ def irunner():
@pytest.mark.parametrize("sync", [True, False])
def test_run_all_tests(irunner, sync):
"""Test running all tests."""
_check_initial_report(irunner.report)

ret = irunner.run_all_tests(await_results=sync)

# If the tests were run asynchronously, await the results.
Expand Down Expand Up @@ -337,12 +337,11 @@ def test_run_all_tagged_tests(tags, num_of_suite_entries):
irunner.teardown()


def _check_initial_report(initial_report):
def test_initial_report(irunner):
"""
Check that the initial report tree is generated correctly.
First, check that there are three top-level Test reports.
"""
initial_report = irunner.report
assert initial_report.status == report.Status.UNKNOWN
assert initial_report.runtime_status == report.RuntimeStatus.READY
assert len(initial_report.entries) == 3
Expand All @@ -366,3 +365,59 @@ def _check_initial_report(initial_report):
param_report = suite_report.entries[1]
assert isinstance(param_report, report.TestGroupReport)
assert len(param_report.entries) == 3


def test_reload_report(irunner):
"""
Tests report reload of the interactive handler.
"""
# We run one of the MultiTests, the suite for another, and only a testcase
# for the third.
irunner.run_test("test_1", await_results=True)
irunner.run_test_suite("test_2", "Suite", await_results=True)
irunner.run_test_case("test_3", "Suite", "case", await_results=True)
# Now we modify the reports forcefully
# In test_2, we add a "case" copy and a "parametrized" copy,
# they need to be removed, while report for "case" and "parametrized"
# should be preserved
case_copy = deepcopy(irunner.report["test_2"]["Suite"].entries[0])
case_copy.uid = "case_copy"
parametrized_copy = deepcopy(irunner.report["test_2"]["Suite"].entries[0])
parametrized_copy.uid = "parametrized_copy"
irunner.report["test_2"]["Suite"].entries.append(parametrized_copy)
# In test_3, we remove "parametrized", it has to be added back
irunner.report["test_3"]["Suite"].entries.pop(1)

# We preserve the current report
old_report = deepcopy(irunner.report)

# We reload and assert
irunner.reload_report()

for test in irunner.report:
# A MultiTest should reset to ready upon changes underneath
assert test.runtime_status == (
RuntimeStatus.READY
if test.uid == "test_3"
else RuntimeStatus.FINISHED
)
for suite in irunner.report[test.uid]:
# A testsuite should reset to ready upon changes underneath
assert suite.runtime_status == (
RuntimeStatus.READY
if test.uid == "test_3"
else RuntimeStatus.FINISHED
)
for index, entry in enumerate(suite):
# We need to check explicitly both "case" and "parametrized" as
# for "test_3" we removed the latter so it needs to come back
assert entry.uid == ("parametrized" if index else "case")
# Common entries are preserved under reload
# keeping conditions explicit if we need to extend later
if (test.uid in ["test_1", "test_2"]) or (
test.uid == "test_3" and entry.uid == "case"
):
check_report(
old_report[test.uid][suite.uid][entry.uid],
irunner.report[test.uid][suite.uid][entry.uid],
)

0 comments on commit 1b3e577

Please sign in to comment.