Skip to content

Detect unittest.fail() calls for assignment warning #10743

@Flamefire

Description

@Flamefire

Current problem

See this example

from unittest import TestCase
import os

class TestX(TestCase):
  def test_foo(self):
    if 'FOO' in os.environ:
        x = 1
    else:
        self.fail()
    print(x) # E0606:possibly-used-before-assignment

Although there is no way to reach the last line without x being unassigned it is reported as such.

Desired solution

self.fail() should be detected as terminating similar to raise ...

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C: used-before-assignmentIssues related to 'used-before-assignment' checkControl flowRequires control flow understandingEnhancement ✨Improvement to a component

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions