Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
Expand Down
9 changes: 8 additions & 1 deletion app/test_calculator.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import random

from .calculator import Calculator


def test_fail():
assert True == False

def test_add():
assert Calculator.add(1, 2) == 3.0
# assert Calculator.add(1, 2) == 3.0
assert Calculator.add(1.0, 2.0) == 3.0
assert Calculator.add(0, 2.0) == 2.0
assert Calculator.add(2.0, 0) == 2.0
Expand All @@ -24,6 +29,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
Loading