How to use check_test_compliance method in Lemoncheesecake

Best Python code snippet using lemoncheesecake

metadatapolicy.py

Source:metadatapolicy.py Github

copy

Full Screen

...119 "In %s '%s', the tag '%s' is not accepted on a %s" % (120 obj_type, obj.path, tag, obj_type121 )122 )123 def check_test_compliance(self, test):124 """125 Check if the test complies to the metadata policy.126 Raise MetadataPolicyViolation if not compliant.127 """128 self._check_compliance(129 test, "test",130 {prop_name: p for prop_name, p in self._properties.items() if p["on_test"]},131 [prop_name for prop_name, p in self._properties.items() if not p["on_test"]],132 {tag_name: t for tag_name, t in self._tags.items() if t["on_test"]},133 [tag_name for tag_name, t in self._tags.items() if not t["on_test"]]134 )135 def check_suite_compliance(self, suite):136 """137 Check if the suite complies to the metadata policy.138 If recursive if set to True (which is the default), then suite tests and sub suites are also checked.139 Raise MetadataPolicyViolation if not compliant.140 """141 self._check_compliance(142 suite, "suite",143 {prop_name: p for prop_name, p in self._properties.items() if p["on_suite"]},144 [prop_name for prop_name, p in self._properties.items() if not p["on_suite"]],145 {tag_name: t for tag_name, t in self._tags.items() if t["on_suite"]},146 [tag_name for tag_name, t in self._tags.items() if not t["on_suite"]]147 )148 for test in suite.get_tests():149 self.check_test_compliance(test)150 def check_suites_compliance(self, suites):151 """152 Check if the suites comply to the metadata policy.153 Raise MetadataPolicyViolation if not compliant.154 """155 for suite in flatten_suites(suites):...

Full Screen

Full Screen

test_metadata_policy.py

Source:test_metadata_policy.py Github

copy

Full Screen

...18 suite = load_suite_from_class(MySuite)19 # passing case20 policy = MetadataPolicy()21 policy.add_property_rule("foo", ("1", "2"), on_test=True, on_suite=True)22 policy.check_test_compliance(suite.get_tests()[0])23 policy.check_suite_compliance(suite)24 # non-passing case25 policy = MetadataPolicy()26 policy.add_property_rule("foo", ("3", "4"), on_test=True, on_suite=True)27 with pytest.raises(MetadataPolicyViolation):28 policy.check_test_compliance(suite.get_tests()[0])29 with pytest.raises(MetadataPolicyViolation):30 policy.check_suite_compliance(suite)31def test_required_property():32 @lcc.prop("foo", "1")33 @lcc.suite("MySuite")34 class MySuite:35 @lcc.prop("foo", "2")36 @lcc.test("Some test")37 def sometest(self):38 pass39 suite = load_suite_from_class(MySuite)40 # passing case41 policy = MetadataPolicy()42 policy.add_property_rule("foo", on_test=True, on_suite=True, required=True)43 policy.check_test_compliance(suite.get_tests()[0])44 policy.check_suite_compliance(suite)45 # non-passing case46 policy = MetadataPolicy()47 policy.add_property_rule("bar", on_test=True, on_suite=True, required=True)48 with pytest.raises(MetadataPolicyViolation):49 policy.check_test_compliance(suite.get_tests()[0])50 with pytest.raises(MetadataPolicyViolation):51 policy.check_suite_compliance(suite)52def test_allowed_properties_and_tags():53 @lcc.prop("foo", "1")54 @lcc.tags("tag1")55 @lcc.suite("MySuite")56 class MySuite:57 @lcc.prop("foo", "2")58 @lcc.tags("tag2")59 @lcc.test("Some test")60 def sometest(self):61 pass62 suite = load_suite_from_class(MySuite)63 # passing case64 policy = MetadataPolicy()65 policy.add_property_rule("foo", on_test=True, on_suite=True)66 policy.add_tag_rule(["tag1", "tag2"], on_test=True, on_suite=True)67 policy.disallow_unknown_properties()68 policy.disallow_unknown_tags()69 policy.check_test_compliance(suite.get_tests()[0])70 policy.check_suite_compliance(suite)71 # non-passing case72 policy = MetadataPolicy()73 policy.add_property_rule("bar", on_test=True, on_suite=True)74 policy.add_tag_rule(["tag3"], on_test=True, on_suite=True)75 policy.disallow_unknown_properties()76 policy.disallow_unknown_tags()77 with pytest.raises(MetadataPolicyViolation):78 policy.check_test_compliance(suite.get_tests()[0])79 with pytest.raises(MetadataPolicyViolation):80 policy.check_suite_compliance(suite)81def test_different_test_and_suite_property_configurations():82 @lcc.prop("foo", "1")83 @lcc.suite("MySuite")84 class MySuite:85 @lcc.prop("bar", "2")86 @lcc.test("Some test")87 def sometest(self):88 pass89 suite = load_suite_from_class(MySuite)90 # passing case91 policy = MetadataPolicy()92 policy.add_property_rule("foo", on_suite=True)93 policy.add_property_rule("bar", on_test=True)94 policy.check_test_compliance(suite.get_tests()[0])95 policy.check_suite_compliance(suite)96 # non-passing case97 policy = MetadataPolicy()98 policy.add_property_rule("foo", on_test=True)99 policy.add_property_rule("bar", on_suite=True)100 with pytest.raises(MetadataPolicyViolation):101 policy.check_test_compliance(suite.get_tests()[0])102 with pytest.raises(MetadataPolicyViolation):103 policy.check_suite_compliance(suite)104def test_different_test_and_suite_tag_configurations():105 @lcc.tags("tag1")106 @lcc.suite("MySuite")107 class MySuite:108 @lcc.tags("tag2")109 @lcc.test("Some test")110 def sometest(self):111 pass112 suite = load_suite_from_class(MySuite)113 # passing case114 policy = MetadataPolicy()115 policy.add_tag_rule("tag1", on_suite=True)116 policy.add_tag_rule("tag2", on_test=True)117 policy.check_test_compliance(suite.get_tests()[0])118 policy.check_suite_compliance(suite)119 # non-passing case120 policy = MetadataPolicy()121 policy.add_tag_rule("tag1", on_test=True)122 policy.add_tag_rule("tag2", on_suite=True)123 with pytest.raises(MetadataPolicyViolation):124 policy.check_test_compliance(suite.get_tests()[0])125 with pytest.raises(MetadataPolicyViolation):126 policy.check_suite_compliance(suite)127def test_disallow_unknown_property():128 @lcc.prop("foo", "1")129 @lcc.suite("MySuite")130 class MySuite:131 @lcc.prop("bar", "2")132 @lcc.test("Some test")133 def sometest(self):134 pass135 suite = load_suite_from_class(MySuite)136 # passing case137 policy = MetadataPolicy()138 policy.check_test_compliance(suite.get_tests()[0])139 policy.check_suite_compliance(suite)140 # non-passing case141 policy = MetadataPolicy()142 policy.disallow_unknown_properties()143 with pytest.raises(MetadataPolicyViolation):144 policy.check_test_compliance(suite.get_tests()[0])145 with pytest.raises(MetadataPolicyViolation):146 policy.check_suite_compliance(suite)147def test_disallow_unknown_tag():148 @lcc.tags("tag1")149 @lcc.suite("MySuite")150 class MySuite:151 @lcc.tags("tag2")152 @lcc.test("Some test")153 def sometest(self):154 pass155 suite = load_suite_from_class(MySuite)156 # passing case157 policy = MetadataPolicy()158 policy.check_test_compliance(suite.get_tests()[0])159 policy.check_suite_compliance(suite)160 # non-passing case161 policy = MetadataPolicy()162 policy.disallow_unknown_tags()163 with pytest.raises(MetadataPolicyViolation):164 policy.check_test_compliance(suite.get_tests()[0])165 with pytest.raises(MetadataPolicyViolation):...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Lemoncheesecake automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful