Skip to content

Commit

Permalink
Merge branch 'main' into feature/suppress_flask_warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
M6AI authored Sep 29, 2023
2 parents 5f9ea64 + e346616 commit f19f20b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 25 deletions.
45 changes: 27 additions & 18 deletions testplan/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,29 +495,13 @@ def test_plan_inner_inner():
**options,
)
try:
if arity(definition) == 2:
returned = definition(plan, plan.parser)
else:
returned = definition(plan)
returned = cls._prepare_plan(definition, plan)
except Exception:
print("Exception in test_plan definition, aborting plan..")
plan.abort()
raise

lister: MetadataBasedLister = plan.cfg.test_lister
if lister is not None and lister.metadata_based:
output = lister.get_output(
TestPlanMetadata(
plan.cfg.name,
plan.cfg.description,
plan.get_test_metadata(),
)
)
if plan.cfg.test_lister_output:
with open(plan.cfg.test_lister_output, "wt") as file:
file.write(output)
else:
TESTPLAN_LOGGER.user_info(output)
cls._do_listing(plan)

plan_result = plan.run()
plan_result.decorated_value = returned
Expand All @@ -527,6 +511,31 @@ def test_plan_inner_inner():

return test_plan_inner

@classmethod
def _prepare_plan(cls, definition, plan):
if arity(definition) == 2:
returned = definition(plan, plan.parser)
else:
returned = definition(plan)
return returned

@classmethod
def _do_listing(cls, plan):
lister: MetadataBasedLister = plan.cfg.test_lister
if lister is not None and lister.metadata_based:
output = lister.get_output(
TestPlanMetadata(
plan.cfg.name,
plan.cfg.description,
plan.get_test_metadata(),
)
)
if plan.cfg.test_lister_output:
with open(plan.cfg.test_lister_output, "wt") as file:
file.write(output)
else:
TESTPLAN_LOGGER.user_info(output)


test_plan = Testplan.main_wrapper

Expand Down
24 changes: 17 additions & 7 deletions testplan/testing/multitest/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from inspect import getsourcefile, getsourcelines
from typing import List, Optional, Union

LOCATION_METADATA_ATTRIBUTE = "__location_metadata__"


@dataclass
class LocationMetadata:
Expand All @@ -11,16 +13,24 @@ class LocationMetadata:
line_no: int

@classmethod
def from_object(cls, obj):
object_name = obj.__name__
file = getsourcefile(obj)
_, line_no = getsourcelines(obj)
return cls(object_name, file, line_no)
def from_object(cls, obj) -> "LocationMetadata":
# some cases where testcases /suites generated on the fly user can provide meaningfull metadata
# with attaching one to the object
if hasattr(obj, LOCATION_METADATA_ATTRIBUTE):
return getattr(obj, LOCATION_METADATA_ATTRIBUTE)
try:
object_name = obj.__name__
file = getsourcefile(obj)
_, line_no = getsourcelines(obj)
except Exception:
return None # we do best effort here
else:
return cls(object_name, file, line_no)


@dataclass
class TestCaseStaticMetadata:
location: LocationMetadata
location: Optional[LocationMetadata]


@dataclass
Expand All @@ -38,7 +48,7 @@ class TestCaseMetadata(TestCaseStaticMetadata, BasicInfo):
@dataclass
class TestSuiteStaticMetadata:

location: LocationMetadata
location: Optional[LocationMetadata]


@dataclass
Expand Down

0 comments on commit f19f20b

Please sign in to comment.