Skip to content
Advertisement

TypeError: test_custom_function..() missing 1 required positional argument: ‘_’

Having a Python functions as below:

JavaScript

and

JavaScript

Run pytest command to receive an error: TypeError: test_GetStudentId..() missing 1 required positional argument: ‘_’

Please help to fix above error. Thanks.

Advertisement

Answer

When calling input you’re passing no arguments (input()), but you’re telling unittest.mock that it has one (lambda _:).
You need to be consistent. Either:

  1. Pass one argument when calling it

    JavaScript
  2. Instruct unittest.mock that function is called with no arguments

    JavaScript

From my PoV, the former makes more sense, as you could also get rid of the print statement before.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement