Skip to content

Refactor exception test to isolate single invocation in test_main.py - #329

Merged
Seppli11 merged 1 commit into
masterfrom
remediate-master-20260824-134542-9c3feef9
Aug 24, 2026
Merged

Refactor exception test to isolate single invocation in test_main.py#329
Seppli11 merged 1 commit into
masterfrom
remediate-master-20260824-134542-9c3feef9

Conversation

@sonarqube-agent

Copy link
Copy Markdown
Contributor

This PR was created because a team member assigned these issues to the Remediation Agent.

Extracted Mock() constructor calls outside the assertRaisesRegex block in test_main.py to ensure only create_scanner_engine() is the invocation being tested for exceptions. This clarifies test intent and resolves the SonarQube code smell that flagged multiple invocations that could potentially throw exceptions within a single exception test block.

View Project in SonarCloud


Fixed Issues

python:S5778 - Refactor this exception test to have only one invocation possibly throwing an exception. • MAJORView issue

Location: tests/unit/test_main.py:168

Why is this an issue?

When writing tests for exception handling, clarity is essential. If you chain multiple method calls within the code being tested for an exception, it becomes ambiguous which specific call is expected to raise that exception.

What changed

This hunk extracts the Mock() constructor calls into separate variables (api and cache) before the assertRaisesRegex block. Previously, Mock() calls were inside the exception-testing block alongside create_scanner_engine(), making it ambiguous which invocation was expected to raise the exception. By moving these calls outside the block, only create_scanner_engine() remains as the single invocation that could throw an exception. This addresses the code smell about having multiple invocations that could possibly throw an exception inside an exception test block.

--- a/tests/unit/test_main.py
+++ b/tests/unit/test_main.py
@@ -166,0 +167,2 @@ class TestMain(pyfakefs.TestCase):
+        api = Mock()
+        cache = Mock()

Have a suggestion or found an issue? Share your feedback here.


SonarQube Remediation Agent uses AI. Check for mistakes.

Fixed issues:
- AaAz4NHds3ud2sinjoFd for python:S5778 rule

Generated by SonarQube Agent (task: 337e4438-7d5f-4d33-9166-7cccf246508e)
@sonarqube-next

Copy link
Copy Markdown

Quality Gate passed Quality Gate passed for 'Python Scanner'

Issues
0 New issues
1 Fixed issue
0 Accepted issues

Measures
0 Security Hotspots
0 Dependency risks
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarQube

@Seppli11
Seppli11 merged commit 75eaee2 into master Aug 24, 2026
21 checks passed
@Seppli11
Seppli11 deleted the remediate-master-20260824-134542-9c3feef9 branch August 24, 2026 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants