Skip to content

Commit

Permalink
a revision on test naming
Browse files Browse the repository at this point in the history
- fix tracing tests mt name output
- fix xfail tests st name matching
- fix task reassign check
- some refactor & typing fix
  • Loading branch information
zhenyu-ms committed Sep 22, 2023
1 parent 69c082d commit ee57f30
Show file tree
Hide file tree
Showing 17 changed files with 155 additions and 125 deletions.
30 changes: 18 additions & 12 deletions testplan/common/report/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
Later on these reports would be merged together to
build the final report as the testplan result.
"""
import copy
import time
import uuid
import collections
import copy
import dataclasses
import itertools

import time
import uuid
from typing import Dict, List, Optional, Union

from testplan.common.utils import strings

from .log import create_logging_adapter


Expand Down Expand Up @@ -57,11 +57,17 @@ class Report:
exception_logger = ExceptionLogger

def __init__(
self, name, description=None, uid=None, entries=None, parent_uids=None
self,
name: str,
description: Optional[str] = None,
instance_name: Optional[str] = None,
uid: Optional[str] = None,
entries: Optional[list] = None,
parent_uids: Optional[List[str]] = None,
):
self.name = name
self.description = description

self.instance_name = instance_name or name
self.uid = uid or name
self.entries = entries or []

Expand All @@ -77,12 +83,12 @@ def __init__(
self.parent_uids = parent_uids or []

def __str__(self):
return '{kls}(name="{name}", id="{uid}")'.format(
return '{kls}(name="{name}", uid="{uid}")'.format(
kls=self.__class__.__name__, name=self.name, uid=self.uid
)

def __repr__(self):
return '{kls}(name="{name}", id="{uid}", entries={entries})'.format(
return '{kls}(name="{name}", uid="{uid}", entries={entries})'.format(
kls=self.__class__.__name__,
name=self.name,
uid=self.uid,
Expand Down Expand Up @@ -131,15 +137,15 @@ def logged_exceptions(self, *exception_classes, **kwargs):

def _check_report(self, report):
"""
Utility method for checking `report` `type` and `uid`.
Utility method for checking `report` `type` and `instance_name`.
"""
msg = "Report check failed for `{}` and `{}`. ".format(self, report)

if report.uid != self.uid:
if report.instance_name != self.instance_name:
raise AttributeError(
msg
+ "`uid` attributes (`{}`, `{}`) do not match.".format(
self.uid, report.uid
+ "`instance_name` attributes (`{}`, `{}`) do not match.".format(
self.instance_name, report.instance_name
)
)

Expand Down
1 change: 1 addition & 0 deletions testplan/common/report/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Meta:

name = fields.String()
description = fields.String(allow_none=True)
instance_name = fields.String(allow_none=True) # otherwise new tpr cannot process old report
entries = fields.List(custom_fields.NativeOrPretty())
parent_uids = fields.List(fields.String())

Expand Down
2 changes: 1 addition & 1 deletion testplan/common/utils/interface.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Validates methods signature."""

from inspect import signature
from typing import Union, Optional
from typing import Union


class NoSuchMethodInClass(Exception):
Expand Down
16 changes: 10 additions & 6 deletions testplan/exporters/testing/coverage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@
import sys
from collections import OrderedDict
from contextlib import contextmanager
from typing import Dict, Generator, Mapping, TextIO, Tuple, Optional
from typing import Dict, Generator, Mapping, Optional, TextIO, Tuple

from testplan.common.exporters import (
ExporterConfig,
ExportContext,
ExporterConfig,
verify_export_context,
)
from testplan.exporters.testing.base import Exporter
from testplan.report.testing.base import (
ReportCategories,
TestCaseReport,
TestGroupReport,
TestReport,
Expand Down Expand Up @@ -52,8 +53,11 @@ def export(
# here we use an OrderedDict as an ordered set
results = OrderedDict()
for entry in source.entries:
if isinstance(entry, TestGroupReport):
self._append_covered_group_n_case(entry, [], results)
if (
isinstance(entry, TestGroupReport)
and entry.category == ReportCategories.MULTITEST
):
self._append_covered_group_n_case(entry, tuple(), results)
if results:
with _custom_open(self.cfg.tracing_tests_output) as (
f,
Expand All @@ -80,15 +84,15 @@ def _append_covered_group_n_case(
Here we use an OrderedDict as an ordered set.
"""
curr_path = (*path, report.name)
curr_path = (*path, report.instance_name)
if report.covered_lines:
result[curr_path] = None
for entry in report.entries:
if isinstance(entry, TestGroupReport):
self._append_covered_group_n_case(entry, curr_path, result)
elif isinstance(entry, TestCaseReport):
if entry.covered_lines:
result[(*curr_path, entry.name)] = None
result[(*curr_path, entry.instance_name)] = None


@contextmanager
Expand Down
18 changes: 11 additions & 7 deletions testplan/exporters/testing/pdf/renderers/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,26 @@
"""
import logging
from collections import OrderedDict
from typing import Optional, Tuple
from typing import Optional, Tuple, Union

from reportlab.lib import colors, styles
from reportlab.platypus import Paragraph

from testplan.common.exporters.pdf import RowStyle
from testplan.common.utils.registry import Registry
from testplan.common.utils.strings import format_description, wrap, split_text
from testplan.common.utils.strings import format_description, split_text, wrap
from testplan.report import (
ReportCategories,
Status,
TestReport,
TestGroupReport,
TestCaseReport,
ReportCategories,
TestGroupReport,
TestReport,
)
from testplan.report.testing.styles import StyleFlag
from testplan.testing import tagging

from . import constants as const
from .base import format_duration, RowData, BaseRowRenderer, MetadataMixin
from .base import BaseRowRenderer, MetadataMixin, RowData, format_duration


class ReportRendererRegistry(Registry):
Expand Down Expand Up @@ -260,6 +261,9 @@ def get_header(
[<TEST_NAME> - <NATIVE TAGS>][][][<TEST_STATUS>]
This method is also used by its subclass, where source will be of type
``TestCaseReport``.
:param source: Source object for the renderer.
:param depth: Depth of the source object on report tree. Used for indentation.
:param row_idx: Index of the current table row to be rendered.
Expand Down Expand Up @@ -417,7 +421,7 @@ def get_header_linestyle(self) -> Tuple[int, colors.HexColor]:

def get_header(
self,
source: TestCaseReport,
source: TestGroupReport,
depth: int,
row_idx: int,
) -> RowData:
Expand Down
11 changes: 11 additions & 0 deletions testplan/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
import copy
import json
import sys
import warnings
from typing import Dict, List

import schema

from testplan import defaults
from testplan.common.utils import logger
from testplan.report.testing import (
Expand Down Expand Up @@ -488,6 +490,15 @@ def process_args(self, namespace: argparse.Namespace) -> Dict:
if args["list"] and not args["test_lister"]:
args["test_lister"] = listing.NameLister()

if (
args["interactive_port"] is not None
and args["tracing_tests"] is not None
):
warnings.warn(
"Tracing tests feature not available in interactive mode."
)
args["tracing_tests"] = None

return args


Expand Down
24 changes: 7 additions & 17 deletions testplan/runnable/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
from typing import (
Any,
Callable,
Collection,
Dict,
List,
MutableMapping,
Optional,
Pattern,
Tuple,
Union,
Collection,
)

import pytz
Expand All @@ -33,11 +33,7 @@
RunnableResult,
RunnableStatus,
)
from testplan.common.exporters import (
BaseExporter,
ExportContext,
run_exporter,
)
from testplan.common.exporters import BaseExporter, ExportContext, run_exporter
from testplan.common.remote.remote_service import RemoteService
from testplan.common.report import MergeError
from testplan.common.utils import logger, strings
Expand All @@ -56,12 +52,12 @@
from testplan.report.testing.styles import Style
from testplan.runnable.interactive import TestRunnerIHandler
from testplan.runners.base import Executor
from testplan.runners.pools.base import Pool
from testplan.runners.pools.tasks import Task, TaskResult
from testplan.runners.pools.tasks.base import is_task_target
from testplan.testing import filtering, listing, ordering, tagging
from testplan.testing.base import Test, TestResult
from testplan.testing.multitest import MultiTest
from testplan.runners.pools.base import Pool


def get_exporters(values):
Expand Down Expand Up @@ -762,7 +758,7 @@ def add(
:rtype: ``str`` or ```NoneType``
"""
local_runner = self.resources.first()
resource: Union[Executor, str, None] = resource or local_runner
resource: str = resource or local_runner

if resource not in self.resources:
raise RuntimeError(
Expand Down Expand Up @@ -1018,12 +1014,11 @@ def _create_result(self):
report.category != ReportCategories.TASK_RERUN
and self.cfg.merge_scheduled_parts
):
report.uid = report.name
# Save the report temporarily and later will merge it
test_rep_lookup.setdefault(report.uid, []).append(
test_rep_lookup.setdefault(report.instance_name, []).append(
(test_results[uid].run, report)
)
if report.uid not in test_report.entry_uids:
if report.instance_name not in test_report.entry_uids:
# Create a placeholder for merging sibling reports
if isinstance(resource_result, TaskResult):
# `runnable` must be an instance of MultiTest since
Expand All @@ -1038,16 +1033,11 @@ def _create_result(self):

else:
report = report.__class__(
report.name,
uid=report.uid,
report.instance_name,
category=report.category,
)
else:
continue # Wait all sibling reports collected
else:
# If do not want to merge sibling reports, then display
# them with different names. (e.g. `MTest - part(0/3)`)
report.name = report.uid

test_report.append(report)
step_result = step_result and run is True # boolean or exception
Expand Down
15 changes: 7 additions & 8 deletions testplan/runnable/interactive/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,19 @@
import re
import threading
from concurrent import futures
from typing import Union, Awaitable, Dict, Optional
from typing import Awaitable, Dict, Optional, Union

from testplan.common import config, entity
from testplan.common.report import Report
from testplan.common.utils import networking

from testplan.runnable.interactive import http, reloader, resource_loader

from testplan.report import (
TestReport,
TestGroupReport,
Status,
ReportCategories,
RuntimeStatus,
Status,
TestGroupReport,
TestReport,
)
from testplan.runnable.interactive import http, reloader, resource_loader


def _exclude_assertions_filter(obj: object) -> bool:
Expand Down Expand Up @@ -567,7 +566,7 @@ def case_filter(obj):
if obj.uid == case_uid:
return True
return obj.uid == suite_uid or (
obj.category == "parametrization"
obj.category == ReportCategories.PARAMETRIZATION
and any(entry.uid == case_uid for entry in obj.entries)
)
except Exception:
Expand Down
Loading

0 comments on commit ee57f30

Please sign in to comment.