canyon289
canyon289

Reputation: 3495

Monkeypatching input causes attribute error during testing

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

Upvotes: 0

Views: 622

Answers (1)

user2357112
user2357112

Reputation: 280778

__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.

Upvotes: 3

Related Questions