Skip to content

Commit cc72846

Browse files
committed
Fixed: Update try/except with specific exceptions and fail the test if the expected exception is not raised
1 parent 4e911a3 commit cc72846

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/python_testing/TC_CGEN_2_2.py

+13-4
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@
4242
from datetime import datetime
4343

4444
import chip.clusters as Clusters
45+
from chip.exceptions import ChipStackError
4546
from chip import ChipDeviceCtrl
47+
from chip.interaction_model import InteractionModelError
4648
from chip.testing.matter_testing import MatterBaseTest, TestStep, async_test_body, default_matter_test_main
4749
from mobly import asserts
4850

@@ -532,8 +534,12 @@ async def test_TC_CGEN_2_2(self):
532534
dev_ctrl=TH2,
533535
node_id=newNodeId,
534536
cmd=cmd)
535-
except Exception as e:
537+
except ChipStackError as e:
538+
asserts.assert_in('Timeout',
539+
str(e), f'Expected Timeout error, but got {str(e)}')
536540
logger.info(f"Step #22 - TH2 Expected error occurred during ArmFailSafe command: {str(e)}. Proceeding to next step.")
541+
else:
542+
asserts.assert_true(False, 'Expected Timeout, but no exception occurred.')
537543

538544
self.step(23)
539545
nocs_updated = await self.read_single_attribute_check_success(
@@ -596,9 +602,12 @@ async def test_TC_CGEN_2_2(self):
596602
cmd = self.cluster_opcreds.Commands.AddTrustedRootCertificate(th2_new_root_cert)
597603
resp = await self.send_single_cmd(dev_ctrl=TH2, node_id=newNodeId+1, cmd=cmd)
598604

599-
except Exception as e:
600-
logger.info(
601-
f"Step #27 - Expected error occurred during TrustedRootCertificate command: {str(e)}. Proceeding to next step.")
605+
except InteractionModelError as e:
606+
asserts.assert_in('FailsafeRequired (0xca)',
607+
str(e), f'Expected FailsafeRequired error, but got {str(e)}')
608+
logger.info(f'Step #27 - Expected error occurred: {str(e)}. Proceeding to next step.')
609+
else:
610+
asserts.assert_true(False, 'Expected InteractionModelError with FailsafeRequired, but no exception occurred.')
602611

603612
self.step(28)
604613
fabrics_updated = await self.read_single_attribute_check_success(

0 commit comments

Comments
 (0)