Repository: resonai/ybt

Issue:
Flags to disable build policies
Allow to run build / test that violate policies using CLI flags

Discussion:

Patch:
diff --git a/yabt/cli.py b/yabt/cli.py
index 9748af8..a007132 100644
--- a/yabt/cli.py
+++ b/yabt/cli.py
@@ -107,6 +107,7 @@ def make_parser(project_config_file: str) -> configargparse.ArgumentParser:
                    help='Disable YBT build cache')
         PARSER.add('--no-docker-cache', action='store_true',
                    help='Disable YBT Docker cache')
+        PARSER.add('--no-policies', action='store_true')
         PARSER.add('--no-test-cache', action='store_true',
                    help='Disable YBT test cache')
         PARSER.add('-v', '--verbose', action='store_true',
@@ -226,7 +227,7 @@ def init_and_get_conf(argv: list=None) -> Config:
     config.flavor_conf = call_user_func(
         config.settings, 'get_flavored_config', config, args)
     call_user_func(config.settings, 'extend_config', config, args)
-    # TODO: condition no "override policies" flag
-    config.policies = listify(call_user_func(
-        config.settings, 'get_policies', config))
+    if not args.no_policies:
+        config.policies = listify(call_user_func(
+            config.settings, 'get_policies', config))
     return config


Test patch:
diff --git a/conftest.py b/conftest.py
index e910f10..be71f74 100644
--- a/conftest.py
+++ b/conftest.py
@@ -116,3 +116,13 @@ def debug_conf():
         '--no-test-cache', '--no-docker-cache', 'build'])
     yabt.extend.Plugin.load_plugins(conf)
     yield conf
+
+
+@yield_fixture
+def nopolicy_conf():
+    reset_parser()
+    conf = cli.init_and_get_conf([
+        '--non-interactive', '--no-build-cache', '--no-test-cache',
+        '--no-docker-cache','--no-policies', 'build'])
+    yabt.extend.Plugin.load_plugins(conf)
+    yield conf
diff --git a/yabt/policy_test.py b/yabt/policy_test.py
index e672c75..00b371d 100644
--- a/yabt/policy_test.py
+++ b/yabt/policy_test.py
@@ -74,3 +74,11 @@ def test_multiple_policy_violations(basic_conf):
             'Invalid licenses for prod policy: GPL-3.0' in err_str)
     # asserting for 2 policy violations
     assert 3 == len(err_str.split('\n'))
+
+
+@pytest.mark.usefixtures('in_error_project')
+def test_disable_policy(nopolicy_conf):
+    nopolicy_conf.targets = ['policy']
+    build_context = BuildContext(nopolicy_conf)
+    populate_targets_graph(build_context, nopolicy_conf)
+    # asserting no exception thrown