Skip to content

Commit

Permalink
Python testing: Add helper functions for marking steps as skipped in …
Browse files Browse the repository at this point in the history
…the TH (#31373)

* Add two new helper functions for marking steps skipped

* python testing: Add helper functions for skipped steps
  • Loading branch information
cecille authored and pull[bot] committed Jul 31, 2024
1 parent e982064 commit 1173000
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 17 deletions.
7 changes: 5 additions & 2 deletions src/python_testing/hello_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ async def test_failure_on_wrong_endpoint(self):

def steps_pics(self) -> list[TestStep]:
steps = [TestStep(1, "Commissioning, already done", is_commissioning=True),
TestStep(2, "Skip this step"),
TestStep(3, "Run this step")
TestStep(2, "Skip this step based on pics"),
TestStep(3, "Run this step"),
TestStep(4, "Always skip this step")
]
return steps

Expand All @@ -90,6 +91,8 @@ async def test_pics(self):
self.step(3)
print('This should also be run')

self.skip_step(4)


if __name__ == "__main__":
default_matter_test_main()
40 changes: 25 additions & 15 deletions src/python_testing/matter_testing_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -862,23 +862,33 @@ def on_pass(self, record):

def pics_guard(self, pics_condition: bool):
if not pics_condition:
try:
steps = self.get_test_steps()
num = steps[self.current_step_index].test_plan_number
except KeyError:
num = self.current_step_index

if self.runner_hook:
# TODO: what does name represent here? The wordy test name? The test plan number? The number and name?
# TODO: I very much do not want to have people passing in strings here. Do we really need the expression
# as a string? Does it get used by the TH?
self.runner_hook.step_skipped(name=str(num), expression="")
else:
logging.info(f'**** Skipping: {num}')
self.step_skipped = True
self.mark_current_step_skipped()

def mark_current_step_skipped(self):
try:
steps = self.get_test_steps(self.current_test_info.name)
if self.current_step_index == 0:
asserts.fail("Script error: mark_current_step_skipped cannot be called before step()")
print(self.current_step_index-1)
num = steps[self.current_step_index-1].test_plan_number
except KeyError:
num = self.current_step_index

if self.runner_hook:
# TODO: what does name represent here? The wordy test name? The test plan number? The number and name?
# TODO: I very much do not want to have people passing in strings here. Do we really need the expression
# as a string? Does it get used by the TH?
self.runner_hook.step_skipped(name=str(num), expression="")
else:
logging.info(f'**** Skipping: {num}')
self.step_skipped = True

def skip_step(self, step):
self.step(step)
self.mark_current_step_skipped()

def step(self, step: typing.Union[int, str]):
test_name = sys._getframe().f_back.f_code.co_name
test_name = self.current_test_info.name
steps = self.get_test_steps(test_name)

# TODO: this might be annoying during dev. Remove? Flag?
Expand Down

0 comments on commit 1173000

Please sign in to comment.