[issue27376] Add mock_import method to mock module

2016-06-23 Thread Eyal Posener

New submission from Eyal Posener:

Add mock_import method.

A helper function to mask ``ImportError``s on a scoped code, using the ``with`` 
statement, or in method a method used as a decorator.
Failed imports will be ignored, unless specified by the *do_not_mock* argument.

The *do_not_mock* argument is a package or module name, or package or module 
names list. When specified, and imported in the scoped mocked code, importing 
them must succeed. If ``None`` (the default) then no import must succeed.

--
components: Library (Lib)
files: mock_import.patch
keywords: patch
messages: 269127
nosy: Eyal Posener
priority: normal
severity: normal
status: open
title: Add mock_import method to mock module
type: enhancement
versions: Python 3.6
Added file: http://bugs.python.org/file43522/mock_import.patch

___
Python tracker 
<http://bugs.python.org/issue27376>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27376] Add mock_import method to mock module

2016-09-01 Thread Eyal Posener

Eyal Posener added the comment:

Thanks for the review, Michael.

About the use case: I use it for a process with loads code and inspect it's 
classes and methods. When I run this process, not always I have all the 
dependencies of the inspected code, so I found myself mocking all those 
packages before running the inspection code. This was very inconvenience, and 
broke any time someone added a new dependency to the code which is not in the 
standard library.

About the name: I agree.

About the keyword for the mock constructor: no problems.

Should I fix the code and submit an updated patch?
Do you think this function has a place in the standard mock module?

--

___
Python tracker 
<http://bugs.python.org/issue27376>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com