diff --git a/detect_secrets/core/secrets_collection.py b/detect_secrets/core/secrets_collection.py index 094a274ed..528f90dfe 100644 --- a/detect_secrets/core/secrets_collection.py +++ b/detect_secrets/core/secrets_collection.py @@ -308,6 +308,10 @@ def __sub__(self, other: Any) -> 'SecretsCollection': return output + def __len__(self) -> int: + """Returns the total number of secrets in the collection.""" + return sum(len(secrets) for secrets in self.data.values()) + def _scan_file_and_serialize(filename: str) -> List[PotentialSecret]: """Used for multiprocessing, since lambdas can't be serialized.""" diff --git a/tests/pre_commit_hook_test.py b/tests/pre_commit_hook_test.py index 84da3e335..632ba1bbb 100644 --- a/tests/pre_commit_hook_test.py +++ b/tests/pre_commit_hook_test.py @@ -98,6 +98,7 @@ def test_console_output(): # Assert formatting output = capturedOutput.getvalue() assert output.startswith('ERROR: Potential secrets about to be committed to git repo!') + assert 'Total secrets detected: 1' in output def test_console_output_json_formatting():