diff --git a/.gitignore b/.gitignore index 98cefe31906..f3e14baa533 100644 --- a/.gitignore +++ b/.gitignore @@ -75,3 +75,7 @@ ocp4/profiles/test.profile # Ignore build profiling data .build_profiling/ + +# Ignore coverage files +.coverage +coverage.xml diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 66cb1f72697..05085833095 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -14,7 +14,6 @@ macro(ssg_python_unit_tests PYTHON_COMPONENT_ID RELATIVE_PYTHONPATH) endmacro() if(PY_PYTEST) - ssg_python_unit_tests("build-scripts" "build-scripts") ssg_python_unit_tests("utils" "utils") ssg_python_unit_tests("ssg-module" ".") ssg_python_unit_tests("ssg_test_suite" "tests") diff --git a/tests/unit/build-scripts/test_relabel_ids.py b/tests/unit/build-scripts/test_relabel_ids.py deleted file mode 100644 index 84669ab45c2..00000000000 --- a/tests/unit/build-scripts/test_relabel_ids.py +++ /dev/null @@ -1,4 +0,0 @@ - - -def test_nothing(): - pass diff --git a/tests/unit/ssg-module/test_build_yaml.py b/tests/unit/ssg-module/test_build_yaml.py index 4a36b6b9c19..88408751f2a 100644 --- a/tests/unit/ssg-module/test_build_yaml.py +++ b/tests/unit/ssg-module/test_build_yaml.py @@ -2,6 +2,7 @@ import collections import os import tempfile +import sys import yaml import pytest @@ -437,6 +438,7 @@ def rule_accounts_tmout(): return ssg.build_yaml.Rule.from_yaml(rule_file) +@pytest.mark.skipif(sys.version_info[0] < 3, reason="requires python3 or higher") def test_rule_to_xml_element(rule_accounts_tmout): xmldiff_main = pytest.importorskip("xmldiff.main") rule_el = rule_accounts_tmout.to_xml_element() @@ -469,6 +471,7 @@ def value_system_crypto_policy(): return ssg.build_yaml.Value.from_yaml(value_file) +@pytest.mark.skipif(sys.version_info[0] < 3, reason="requires python3 or higher") def test_value_to_xml_element(value_system_crypto_policy): xmldiff_main = pytest.importorskip("xmldiff.main") value_el = value_system_crypto_policy.to_xml_element() diff --git a/tests/unit/ssg-module/test_controls.py b/tests/unit/ssg-module/test_controls.py index 2f724bc63e8..d6573ce4578 100644 --- a/tests/unit/ssg-module/test_controls.py +++ b/tests/unit/ssg-module/test_controls.py @@ -1,6 +1,7 @@ import pytest import logging import os +import sys import ssg.controls import ssg.build_yaml @@ -98,6 +99,7 @@ def test_controls_load(controls_manager): _load_test(controls_manager, "abcd") +@pytest.mark.skipif(sys.version_info[0] < 3, reason="requires python3 or higher") def test_controls_invalid_rules(env_yaml): existing_rules = {"accounts_tmout", "configure_crypto_policy"} controls_manager = ssg.controls.ControlsManager( @@ -107,6 +109,8 @@ def test_controls_invalid_rules(env_yaml): assert str(exc.value) == \ "Control abcd:R1 contains nonexisting rule(s) sshd_set_idle_timeout" + +@pytest.mark.skipif(sys.version_info[0] < 3, reason="requires python3 or higher") def test_controls_levels(controls_manager): # Default level is the lowest level c_1 = controls_manager.get_control("abcd-levels", "S1") diff --git a/tox.ini b/tox.ini index 32f58c29a6c..7af7dd16b28 100644 --- a/tox.ini +++ b/tox.ini @@ -1,44 +1,60 @@ [tox] -envlist = py27,py3{6,7,8,9,10,11},flake8,docs +envlist = coverage_clean, py27, py3{6, 8, 9}, py3, coverage_report, flake8 skip_missing_interpreters = true isolated_build = true skipsdist = true -[flake8] -max-line-length = 99 - +# Unit tests [testenv] +setenv = + tests_dir = {toxinidir}{/}tests/unit + PYTHONPATH = {toxinidir} +commands = + python -m pytest --cov-append --cov-report=xml --cov=ssg "{env:tests_dir}{/}ssg-module" + +deps = + pyyaml + Jinja2 + -r test-requirements.txt + +# Coverage +[testenv:coverage_report] +deps = coverage skip_install = true -install_command = pip install {opts} {packages} +commands = + coverage html + coverage xml + coverage report -m + +[testenv:coverage_clean] +deps = coverage +skip_install = true +commands = coverage erase + + +# Code style +[flake8] +max-line-length = 99 +per-file-ignores =__init__.py:F401 [testenv:flake8] -basepython = python3 commands = - flake8 ssg utils + flake8 ssg utils tests build-scripts deps = flake8 +# Documentation [testenv:docs] -skip_install=false -skipsdist=true basepython = python3 allowlist_externals = make + rm deps = -r docs/requirements.txt +commands_pre = + make -C docs clean + rm -rf docs/api commands = make -C docs html commands_post = make -C docs linkcheck - -[testenv:clean] -skip_install = true -allowlist_externals = - bash - -deps = - pip>=21.1 - -commands = - bash -c 'make -C docs/ clean' - bash -c 'rm -rf dist/ build/* docs/api/'