Skip to content

Commit f4c99ba

Browse files
Skip load custom tests step if no custom tests were found (#288)
* Skip load custom tests step if no custom tests were found * Update test_collections/matter/sdk_tests/support/python_testing/test_manager.py Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent ccbbf58 commit f4c99ba

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

test_collections/matter/sdk_tests/support/python_testing/test_manager.py

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,19 @@
3434
logger = logging.getLogger(__name__)
3535

3636

37+
def _has_custom_tests() -> bool:
38+
"""Check if custom test folder contains any test files.
39+
40+
Returns:
41+
True if custom folder has test files matching the pattern, False otherwise
42+
"""
43+
if not CUSTOM_PYTHON_SCRIPTS_FOLDER.path.exists():
44+
return False
45+
46+
# Check if any files match the TC* pattern in the custom folder
47+
return any(CUSTOM_PYTHON_SCRIPTS_FOLDER.path.glob("TC*.py"))
48+
49+
3750
def _update_module_collections(
3851
sdk_collection: TestCollectionDeclaration,
3952
mandatory_collection: TestCollectionDeclaration,
@@ -77,13 +90,19 @@ async def _generate_all_test_files() -> None:
7790
await generate_python_test_json_file(grouped_commands=True)
7891
logger.info("Standard SDK tests generated successfully")
7992

80-
# Generate custom tests using the same container session context
81-
await generate_python_test_json_file(
82-
test_folder=CUSTOM_PYTHON_SCRIPTS_FOLDER,
83-
json_output_file=CUSTOM_PYTHON_TESTS_PARSED_FILE,
84-
grouped_commands=True,
85-
)
86-
logger.info("Custom tests generated successfully")
93+
# Only generate custom tests if custom folder has test files
94+
if _has_custom_tests():
95+
await generate_python_test_json_file(
96+
test_folder=CUSTOM_PYTHON_SCRIPTS_FOLDER,
97+
json_output_file=CUSTOM_PYTHON_TESTS_PARSED_FILE,
98+
grouped_commands=True,
99+
)
100+
logger.info("Custom tests generated successfully")
101+
else:
102+
logger.info("No custom tests found, skipping custom test generation")
103+
# Clean custom test JSON file by writing empty structure
104+
CUSTOM_PYTHON_TESTS_PARSED_FILE.write_text('{"tests": []}')
105+
logger.info(f"Cleaned custom test file: {CUSTOM_PYTHON_TESTS_PARSED_FILE}")
87106

88107
except Exception as e:
89108
logger.error(f"Failed to generate test files: {e}")

0 commit comments

Comments
 (0)