Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions test_validate_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ def test_validate_success():
# Should not raise any exception
validate()

def test_validate_empty_list():
"""Test validate() with an empty JSON array."""
mock_data = json.dumps([])
with patch("builtins.open", mock_open(read_data=mock_data)):
# Should not raise any exception
validate()
Comment on lines +16 to +18
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To improve the robustness of the test, consider verifying that the validate function opens the expected file (testing_report.json) with the correct mode ('r'). This ensures the function is interacting with the filesystem as intended and provides a more thorough validation than just checking for the absence of exceptions.

Suggested change
with patch("builtins.open", mock_open(read_data=mock_data)):
# Should not raise any exception
validate()
with patch("builtins.open", mock_open(read_data=mock_data)) as mock_file:
# Should not raise any exception
validate()
mock_file.assert_called_once_with('testing_report.json', 'r')


def test_validate_not_a_list():
"""Test validate() when root is not a JSON array."""
mock_data = json.dumps({"id": 1, "status": "pass"})
Expand Down