0

I've searched all over the place, and I feel like I am missing something super basic.

I have the code below, and I think I have the test written, but I can't figure out the right argument to add when calling the test_input() function.

I am getting the error: File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0\lib\unittest\mock.py", line 1325, in patched return func(*newargs, **newkeywargs) TypeError: test_input() missing 1 required positional argument: 'mock_input'

def input_something():
    input("Enter something")

@patch('builtins.input',return_value = 1)
def test_input(self, mock_input):
    result = input_something()
    self.assertEqual(result, 1)

test_input()
speroni1
  • 63
  • 1
  • 4
  • That `test_input` should be declared as a method inside a `unittest.TestCase` subclass, not as a standalone function, as `self` should be one of those instance. See [this thread](https://stackoverflow.com/questions/21046717/python-mocking-raw-input-in-unittests) for a complete example. If you insist on a standalone function (without using `TestCase` subclass), refer to [this answer](https://stackoverflow.com/a/37467870/2904896) for usage as a context manager. – metatoaster Nov 11 '20 at 03:52
  • If you use the first answer to the second link (this answer) as below, how do you call Test.test_input()? I get the same error this way. `def input_something(): input("Enter something") class Test(TestCase): @patch('builtins.input',return_value = 1) def test_input(self, mock_input): result = input_something() self.assertEqual(result, 2) Test.test_input()` – speroni1 Nov 11 '20 at 04:15
  • by chance I figured out the answer.... instead of "test_input()" put "unittest.main()" – speroni1 Nov 11 '20 at 04:36

1 Answers1

0

by chance I figured out the answer.... instead of "test_input()" put "unittest.main()"

speroni1
  • 63
  • 1
  • 4