From d3e46d6b8657308928486d5481f28a5272bdfe18 Mon Sep 17 00:00:00 2001 From: Zhenyu Yao <111329301+zhenyu-ms@users.noreply.github.com> Date: Thu, 2 May 2024 15:27:17 +0800 Subject: [PATCH] Fix/wrong report category type (#1079) --- testplan/testing/base.py | 3 ++- .../testplan/testing/fixtures/base/failing/report.py | 2 +- .../testplan/testing/fixtures/base/passing/report.py | 2 +- .../testing/fixtures/base/sleeping/report.py | 2 +- tests/functional/testplan/testing/test_base.py | 10 +++++++++- .../functional/testplan/testing/test_environment.py | 11 ++--------- tests/unit/testplan/test_plan_base.py | 7 +++++++ tests/unit/testplan/testing/test_base.py | 12 +++++++++--- tests/unit/testplan/testing/test_pytest.py | 3 +++ 9 files changed, 35 insertions(+), 17 deletions(-) diff --git a/testplan/testing/base.py b/testplan/testing/base.py index 50a008a4d..8cf0f1573 100644 --- a/testplan/testing/base.py +++ b/testplan/testing/base.py @@ -232,7 +232,8 @@ def _new_test_report(self) -> TestGroupReport: return TestGroupReport( name=self.cfg.name, description=self.cfg.description, - category=self.__class__.__name__.lower(), + # TODO: lift to class var? + category=ReportCategories(self.__class__.__name__.lower()), tags=self.cfg.tags, env_status=ResourceStatus.STOPPED, ) diff --git a/tests/functional/testplan/testing/fixtures/base/failing/report.py b/tests/functional/testplan/testing/fixtures/base/failing/report.py index 225d574ab..e0b0391d3 100644 --- a/tests/functional/testplan/testing/fixtures/base/failing/report.py +++ b/tests/functional/testplan/testing/fixtures/base/failing/report.py @@ -27,7 +27,7 @@ entries=[ TestGroupReport( name="MyTest", - category="dummytest", + category="unittest", entries=[ TestGroupReport( name="ProcessChecks", diff --git a/tests/functional/testplan/testing/fixtures/base/passing/report.py b/tests/functional/testplan/testing/fixtures/base/passing/report.py index 265ebc5a2..ddd87fc98 100644 --- a/tests/functional/testplan/testing/fixtures/base/passing/report.py +++ b/tests/functional/testplan/testing/fixtures/base/passing/report.py @@ -27,7 +27,7 @@ entries=[ TestGroupReport( name="MyTest", - category="dummytest", + category="unittest", entries=[ TestGroupReport( name="ProcessChecks", diff --git a/tests/functional/testplan/testing/fixtures/base/sleeping/report.py b/tests/functional/testplan/testing/fixtures/base/sleeping/report.py index 35ad2b56d..c9b3f9b63 100644 --- a/tests/functional/testplan/testing/fixtures/base/sleeping/report.py +++ b/tests/functional/testplan/testing/fixtures/base/sleeping/report.py @@ -25,7 +25,7 @@ my_test_report = TestGroupReport( name="MyTest", - category="dummytest", + category="unittest", entries=[ TestGroupReport( name="ProcessChecks", diff --git a/tests/functional/testplan/testing/test_base.py b/tests/functional/testplan/testing/test_base.py index 1a136e93e..a5952ee84 100644 --- a/tests/functional/testplan/testing/test_base.py +++ b/tests/functional/testplan/testing/test_base.py @@ -1,5 +1,4 @@ import os -import platform import pytest @@ -7,7 +6,9 @@ from testplan.testing.multitest.driver.base import Driver, DriverConfig from testplan.common.config import ConfigOption +from testplan.common.report import ReportCategories from testplan.common.utils.testing import check_report +from testplan.report.testing import TestGroupReport from .fixtures import base @@ -33,6 +34,13 @@ def myvalue(self): class DummyTest(ProcessRunnerTest): + def _new_test_report(self): + return TestGroupReport( + name=self.cfg.name, + # NOTE: unexpected usage, test only + category=ReportCategories.UNITTEST, + ) + def should_run(self): return True diff --git a/tests/functional/testplan/testing/test_environment.py b/tests/functional/testplan/testing/test_environment.py index 1cf0b045c..8afe40a33 100644 --- a/tests/functional/testplan/testing/test_environment.py +++ b/tests/functional/testplan/testing/test_environment.py @@ -6,9 +6,10 @@ from pytest_test_filters import skip_on_windows from testplan.runners.pools.process import ProcessPool -from testplan.testing.base import ProcessRunnerTest from testplan.testing.multitest.driver.base import Driver +from .test_base import DummyTest + @pytest.fixture def named_temp_file(): @@ -39,14 +40,6 @@ def post_start(self): super().post_start() -class DummyTest(ProcessRunnerTest): - def process_test_data(self, _): - return [] - - def read_test_data(self): - pass - - binary_path = os.path.join( os.path.dirname(__file__), "fixtures", "base", "passing", "test.sh" ) diff --git a/tests/unit/testplan/test_plan_base.py b/tests/unit/testplan/test_plan_base.py index 48ebb17d0..de5e77b13 100644 --- a/tests/unit/testplan/test_plan_base.py +++ b/tests/unit/testplan/test_plan_base.py @@ -48,6 +48,13 @@ def __init__(self, name="dummyTest"): self.resources.add(DummyDriver(), uid=self.name) self.resources.add(DummyDriver()) + def _new_test_report(self): + return TestGroupReport( + name=self.cfg.name, + # NOTE: unexpected usage, test only + category=ReportCategories.UNITTEST, + ) + def run_tests(self): self.result.custom = "{}Result[{}]".format( self.__class__.__name__, self.name diff --git a/tests/unit/testplan/testing/test_base.py b/tests/unit/testplan/testing/test_base.py index 983ed1dbe..5804a430d 100644 --- a/tests/unit/testplan/testing/test_base.py +++ b/tests/unit/testplan/testing/test_base.py @@ -1,8 +1,7 @@ import time from testplan import TestplanMock -from testplan.common.entity import Runnable -from testplan.report import Status +from testplan.report import Status, ReportCategories, TestGroupReport from testplan.runnable import TestRunnerStatus from testplan.runners.local import LocalRunner from testplan.testing.base import Test, TestResult @@ -28,6 +27,13 @@ def __init__(self, name, **options): **options ) + def _new_test_report(self): + return TestGroupReport( + name=self.cfg.name, + # NOTE: unexpected usage, test only + category=ReportCategories.UNITTEST, + ) + def run_tests(self): with self.result.report.timer.record("run"): time.sleep(0.5) # 500ms for execution @@ -82,7 +88,7 @@ def test_time_information(): assert res.run is True test_report = res.report["Dummy"] - assert test_report.name == "Dummy" and test_report.category == "dummytest" + assert test_report.name == "Dummy" and test_report.category == "unittest" assert ( test_report.timer.last(key="setup").elapsed > 0.4 ) # 2 drivers startup diff --git a/tests/unit/testplan/testing/test_pytest.py b/tests/unit/testplan/testing/test_pytest.py index f07d343ad..34f44e034 100644 --- a/tests/unit/testplan/testing/test_pytest.py +++ b/tests/unit/testplan/testing/test_pytest.py @@ -6,6 +6,7 @@ from testplan import defaults, report from testplan.report import TestCaseReport +from testplan.report.testing.schemas import TestGroupReportSchema from testplan.testing import py_test as pytest_runner from tests.unit.testplan.testing import pytest_expected_data @@ -54,6 +55,8 @@ def test_run_tests(pytest_test_inst): ] ) _check_all_testcounts(pytest_test_inst.report.counter) + # NOTE: check if valid JSON5? + _ = TestGroupReportSchema().dump(pytest_test_inst.report) def test_run_testcases_iter_all(pytest_test_inst):