diff --git a/tests/unit/utils/test_generate_most_used_rules.py b/tests/unit/utils/test_generate_most_used_rules.py index 7900093bebde..d213fd6c0ea8 100644 --- a/tests/unit/utils/test_generate_most_used_rules.py +++ b/tests/unit/utils/test_generate_most_used_rules.py @@ -1,4 +1,6 @@ import os +import sys +import pytest from argparse import Namespace from utils.profile_tool import command_most_used_rules @@ -14,6 +16,7 @@ def get_fake_args(): ) +@pytest.mark.skipif(sys.version_info[0] < 3, reason="requires python3") def test_command(capsys): command_most_used_rules(get_fake_args()) captured = capsys.readouterr() diff --git a/utils/profile_tool/most_used_rules.py b/utils/profile_tool/most_used_rules.py index d75df6e0fd17..e9899836fd1c 100644 --- a/utils/profile_tool/most_used_rules.py +++ b/utils/profile_tool/most_used_rules.py @@ -1,12 +1,18 @@ +import sys import json from ssg.build_profile import XCCDFBenchmark -from .profile import get_profile -from ..controleval import ( - load_controls_manager, - get_available_products, - get_product_profiles_files, -) + + +PYTHON_2 = sys.version_info[0] < 3 + +if not PYTHON_2: + from .profile import get_profile + from ..controleval import ( + load_controls_manager, + get_available_products, + get_product_profiles_files, + ) def _count_rules_per_rules_list(rules_list, rules): @@ -52,10 +58,12 @@ def command_most_used_rules(args): rules = {} if len(args.BENCHMARKS) == 0: + if PYTHON_2: + raise Exception("This feature is not supported for python2.") _process_all_products_from_controls(rules) - else: - for benchmark in args.BENCHMARKS: - _count_rules_per_benchmark(benchmark, rules) + + for benchmark in args.BENCHMARKS: + _count_rules_per_benchmark(benchmark, rules) sorted_rules = _sorted_rules(rules)