3

When I use unittest in python, I get the error message:

test_update() missing 1 required positional argument: 'mock_stdout'

Below is my code for test_update:

def test_update(self, mock_stdout):
    """Test update information"""
    new_geo="CANADA"
    new_commodity= "SUGAR"
    new_value = "7.81"
    new_ref_date = "2018"
    new_vector ="v1574617"
    new_coordinate = "1.49"
    update = Modify()

    with mock.patch(
        'builtins.input',
        side_effect=[new_ref_date, new_geo, new_commodity,
                     new_vector, new_coordinate, new_value]):
      update.update()
      self.assertEqual(
          mock_stdout.getvalue(),
          "Update information for database\n" +
            "3 row(s) updated\n" + 
            "|2018|CANADA|SUGER|v1574617|1.49|7.81|\n" +
            "|2018|CANADA|SUGER|v1574617|1.49|7.81|\n" +
            "|2018|CANADA|SUGER|v1574617|1.49|7.81|\n" +
            "========================================\n")
martineau
  • 119,623
  • 25
  • 170
  • 301
Richard
  • 31
  • 1
  • 2

1 Answers1

0

As mentioned in this answer to the question Python unittest passing arguments, the problem here seems to be that you are trying to pass in a mock_stdout argument to the function (def test_update(self, mock_stdout):). Try moving the definition of mock_stdout to outside the function, like this:

mock_stdout = <fill this in>


def test_update(self):  # Removed mock_stdout from the list of arguments
    ...
Nathan Wailes
  • 9,872
  • 7
  • 57
  • 95