0

I'm trying to monkeypatch in pytest the input function to simulate user input but I'm getting an attribute error.

I receive the same error when I use the mock.patch.object as well. But I'm able to readily monkeypatch the input when I'm in a regular Python environment, I only get this error in testing.enter image description here

What could be causing this issue?

Edit Adding additional screenshot trying same thing using unittest.mock Unittestmockerror

canyon289
  • 3,355
  • 4
  • 33
  • 41

1 Answers1

3

__builtins__ is an implementation detail. You shouldn't touch it. What you're looking for is either the __builtin__ (no s) or builtins module, depending on whether you're on Python 2 or 3.

Judging by the details of the error you got, you're on Python 3, so you want builtins.

user2357112
  • 260,549
  • 28
  • 431
  • 505
  • I'm on Python3 but I need to replace the input() function with one that returns a fake input. Trying to this without using a decorator or mock module http://stackoverflow.com/questions/18161330/using-unittest-mock-to-patch-input-in-python-3 – canyon289 Jul 14 '16 at 18:45
  • @canyon289 I'm confused. You provided a link that has two answers using a decorator and uses mock. And if you are looking for input to return a fake input, you are mocking input's functionality. So, I'm not sure what it is you are trying to do exactly. – idjaw Jul 14 '16 at 18:49
  • One parts of my program takes a user input and returns a value. I'm trying to test using pytest and part of that test is having the input function return a value. To automate that test I'm trying to monkeypatch/mock the regular input function with one that will return a string set in the test. I get this same error whether I use the mock module or the pytest monkeypatch function – canyon289 Jul 14 '16 at 18:53