diff --git a/requirements.txt b/requirements.txt index ec9286c3..e694e393 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,4 +3,5 @@ pre-commit==3.3.3 pytest==7.4.0 PyYAML==6.0.1 yamllint==1.32.0 -gitpython==3.1.32 \ No newline at end of file +gitpython==3.1.32 +psutil==5.9.5 \ No newline at end of file diff --git a/tests/definitions_test.py b/tests/definitions_test.py index 3105c098..650bcf6f 100644 --- a/tests/definitions_test.py +++ b/tests/definitions_test.py @@ -1,4 +1,4 @@ -from test_configuration import COMPONENT_TYPES, IMAGE_FILETYPES, SCHEMAS, KNOWN_SLUGS, ROOT_DIR, USE_LOCAL_KNOWN_SLUGS, NETBOX_DT_LIBRARY_URL, KNOWN_MODULES, USE_UPSTREAM_DIFF +from test_configuration import COMPONENT_TYPES, IMAGE_FILETYPES, SCHEMAS, KNOWN_SLUGS, ROOT_DIR, USE_LOCAL_KNOWN_SLUGS, NETBOX_DT_LIBRARY_URL, KNOWN_MODULES, USE_UPSTREAM_DIFF, PRECOMMIT_ALL_SWITCHES import pickle_operations from yaml_loader import DecimalSafeLoader from device_types import DeviceType, ModuleType, verify_filename, validate_components @@ -7,6 +7,7 @@ import glob import json import os import tempfile +import psutil from urllib.request import urlopen import pytest @@ -105,7 +106,11 @@ def test_environment(): if definition_files: pytest.skip("No changes to definition files found.") -if USE_UPSTREAM_DIFF: +EVALUATE_ALL = False +if any(x in PRECOMMIT_ALL_SWITCHES for x in psutil.Process(os.getppid()).cmdline()): + EVALUATE_ALL = True + +if USE_UPSTREAM_DIFF and not EVALUATE_ALL: definition_files = _get_diff_from_upstream() else: definition_files = _get_definition_files() @@ -120,6 +125,7 @@ else: KNOWN_SLUGS = pickle_operations.read_pickle_data(f'{temp_dir.name}/tests/known-slugs.pickle') KNOWN_MODULES = pickle_operations.read_pickle_data(f'{temp_dir.name}/tests/known-modules.pickle') + @pytest.mark.parametrize(('file_path', 'schema'), definition_files) def test_definitions(file_path, schema): """ diff --git a/tests/test_configuration.py b/tests/test_configuration.py index afae3845..7ef02efe 100644 --- a/tests/test_configuration.py +++ b/tests/test_configuration.py @@ -21,6 +21,11 @@ COMPONENT_TYPES = ( 'module-bays', ) +PRECOMMIT_ALL_SWITCHES = [ + '-a', + '--all-files' +] + ROOT_DIR = os.path.abspath(os.path.join(os.path.dirname( __file__ ), '..')) KNOWN_SLUGS = set()