Skip to content
Closed
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions app/test_calculator.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import random

from .calculator import Calculator


Expand All @@ -24,6 +26,8 @@ def test_multiply():
assert Calculator.multiply(-4, 2.0) == -8.0

def test_divide():
if random.random() < 0.2:
assert True == False
Comment on lines +32 to +33

Choose a reason for hiding this comment

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

Potential bug: The test test_divide will fail non-deterministically approximately 20% of the time due to a random assertion failure, causing CI/CD pipelines to fail unpredictably.
  • Description: The test_divide function includes a conditional statement if random.random() &lt; 0.2: assert True == False. This introduces a non-deterministic failure, causing the test to fail approximately 20% of the time it is run. Since the CI/CD pipeline executes tests on every push and pull request, this will lead to random pipeline failures. These failures will block pull requests and deployments unpredictably, requiring developers to re-run jobs or investigate spurious failures, which erodes confidence in the test suite.

  • Suggested fix: Remove the conditional block that causes the random assertion failure: if random.random() &lt; 0.2: assert True == False. Tests should be deterministic to ensure reliable and repeatable results.
    severity: 0.75, confidence: 1.0

Did we get this right? 👍 / 👎 to inform future reviews.

# assert Calculator.divide(1, 2) == 0.5
assert Calculator.divide(1.0, 2.0) == 0.5
assert Calculator.divide(0, 2.0) == 0
Expand Down