All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.l10n.py.rules.python.S5915.html Maven / Gradle / Ivy

There is a newer version: 4.23.0.17664
Show newest version

Why is this an issue?

Using pytest.raises or unittest.TestCase.assertRaises will assert that an exception is raised in the following block. Ending such block in an assertion means that the test can succeed with that last assertion never being executed.

Noncompliant code example

import pytest
def foo(): return 1 / 0
def bar(): return 42
def test_something():
  with pytest.raises(ZeroDivisionError):
    foo()
    assert bar() == 42  # Noncompliant

Compliant solution

import pytest
def foo(): return 1 / 0
def bar(): return 42
def test_something():
  with pytest.raises(ZeroDivisionError):
    foo()
  assert bar() == 42

Resources





© 2015 - 2024 Weber Informatics LLC | Privacy Policy