Details

    • Type: Code Smell Detection
    • Status: Active
    • Resolution: Unresolved
    • Message:
      Skip this test explicitly.
    • Highlighting:
      Hide

      The return statement

      Show
      The return statement
    • Default Severity:
      Minor
    • Impact:
      Low
    • Likelihood:
      Low
    • Targeted languages:
      Python
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      2min
    • Analysis Scope:
      Test Sources

      Description

      Test frameworks provide a mechanism to skip tests if their prerequisites are not met, by either calling dedicated methods (e.g: unittest.TestCase.skipTest, pytest.skip, ...) or using decorators (e.g: unittest.skip, pytest.mark.skip, ...)

      Using a return statement instead will make the test succeed, even though no assertion has been performed. It is therefore better to flag the test as skipped in such situation.

      This rule raises an issue when a return is performed conditionally at the beginning of a test method.

      No issue will be raised if the return is unconditional as S1763 already raises an issue in such case.

      The supported frameworks are Pytest and Unittest.

      Noncompliant Code Example

      import unittest
      class MyTest(unittest.TestCase):
      
          def test_something(self):
              if not external_resource_available():
                  return  # Noncompliant
              self.assertEqual(foo(), 42)
      

      Compliant Solution

      import unittest
      class MyTest(unittest.TestCase):
      
          def test_something(self):
              if not external_resource_available():
                  self.skipTest("prerequisite not met")
              self.assertEqual(foo(), 42)
      

      See

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                guillaume.dequenne Guillaume Dequenne
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated: