-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mock.patch with py2 and p3 #1598
Comments
Thanks for reporting. I assume if you pass Either way I think mocking builtins like |
I wouldnt say it works :P I mean i dont get any errors but i have to manually write in the cli inputs so its kinda useless. I have simply disabled he cli tests for python3 as a work around. Ill find another way to solve this I only rename do i can support both python 2 and 3 in my script. Thanks for your work on py test. Its awesome |
I see. If you want a workaround: in situations where I want to mock a builtin and that's a problem for some reason, I usually write a thin wrapper and use that in my code: def obtain_input(text):
return input(text)
def delete_file():
response = obtain_input('continue?')
... This way you can easily mock the thin wrapper instead on the tests themselves: @pytest.yield_fixture
def fake_input():
with mock.patch('module.obtain_input') as m:
yield m
def test_delete_file(fake_input):
fake_input.return_value = 'y'
module.delete_file()
assert module.file_exists() Just an idea. 😁 |
Thanks for the suggestion. I ended up with replacing the renamed input/raw_input with
Ill close this because of the issue you opened. |
(bandit will flag the use of input() in python 2 as a high severity security issue otherwise) Also adds a wrapper as a workaround for pytest-dev/pytest#1598
(bandit will flag the use of input() in python 2 as a high severity security issue otherwise) Also adds a wrapper as a workaround for pytest-dev/pytest#1598
(bandit will flag the use of input() in python 2 as a high severity security issue otherwise) Also adds a wrapper as a workaround for pytest-dev/pytest#1598
(bandit will flag the use of input() in python 2 as a high severity security issue otherwise) Also adds a wrapper as a workaround for pytest-dev/pytest#1598
(bandit will flag the use of input() in python 2 as a high severity security issue otherwise) Also adds a wrapper as a workaround for pytest-dev/pytest#1598
Thanks for submitting an issue!
Here's a quick checklist in what to include:
Im wondering if there is a bug in pytest. I get a exception when i try to rename input or raw input depending on the python version.
pip list
of the virtual environment you are usingpy3
py2 list
Test script to recreate the error
py2 with raw_input renamed to input:
py3 with input
The text was updated successfully, but these errors were encountered: