Best Python code snippet using lemoncheesecake
metadatapolicy.py
Source:metadatapolicy.py  
...18            return True, False19        if not on_test and not on_suite:20            raise AssertionError("either on_test or on_suite need to be True")21        return bool(on_test), bool(on_suite)22    def add_property_rule(self, prop_name, accepted_values=None, on_test=None, on_suite=None, required=False):23        """24        Declare a property rule.25        :param prop_name: the property name26        :param accepted_values: an optional list of accepted values27        :param on_test: whether or not the property can be used on a test28        :param on_suite: whether or not the property can be used on a suite29        :param required: whether or not the property is required30        If neither on_test or on_suite argument are set, then the property is only available for tests.31        """32        on_test, on_suite = self._get_rule_application(on_test, on_suite)33        self._properties[prop_name] = {34            "values": accepted_values,35            "on_test": on_test,36            "on_suite": on_suite,...project.py
Source:project.py  
...13        return "ECHO tests (ECHO v. {})".format(echo_image_version)14project_dir = os.path.dirname(__file__)15sys.path.append(project_dir)16project = MyProject(project_dir)17project.metadata_policy.add_property_rule("main", "type", on_suite=True, required=False)18project.metadata_policy.add_property_rule("positive", "type", on_suite=True, required=False)19project.metadata_policy.add_property_rule("negative", "type", on_suite=True, required=False)20RESOURCES_DIR = os.path.join(os.path.dirname(__file__), "resources")21genesis_path = "genesis.json" if "GENESIS_FILE" not in os.environ else os.environ["GENESIS_FILE"]22GENESIS = json.load(open(os.path.join(os.path.dirname(__file__), genesis_path)))23if "ROPSTEN" in os.environ and os.environ["ROPSTEN"].lower() != "false":24    ROPSTEN = True25else:26    ROPSTEN = False27if "DEBUG" in os.environ and os.environ["DEBUG"].lower() != "false":28    DEBUG = True29else:30    DEBUG = False31if "BASE_URL" not in os.environ:32    BASE_URL = json.load(open(os.path.join(RESOURCES_DIR, "urls.json")))["BASE_URL"]33else:...test_metadata_policy.py
Source:test_metadata_policy.py  
...17            pass18    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 case...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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
