Skip to content

Commit

Permalink
Fix/wrong report category type (#1079)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhenyu-ms authored May 2, 2024
1 parent 2fbe745 commit d3e46d6
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 17 deletions.
3 changes: 2 additions & 1 deletion testplan/testing/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
entries=[
TestGroupReport(
name="MyTest",
category="dummytest",
category="unittest",
entries=[
TestGroupReport(
name="ProcessChecks",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
entries=[
TestGroupReport(
name="MyTest",
category="dummytest",
category="unittest",
entries=[
TestGroupReport(
name="ProcessChecks",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

my_test_report = TestGroupReport(
name="MyTest",
category="dummytest",
category="unittest",
entries=[
TestGroupReport(
name="ProcessChecks",
Expand Down
10 changes: 9 additions & 1 deletion tests/functional/testplan/testing/test_base.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import os
import platform

import pytest

from testplan.testing.base import ProcessRunnerTest
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

Expand All @@ -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

Expand Down
11 changes: 2 additions & 9 deletions tests/functional/testplan/testing/test_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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"
)
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/testplan/test_plan_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 9 additions & 3 deletions tests/unit/testplan/testing/test_base.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/testplan/testing/test_pytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit d3e46d6

Please sign in to comment.