[issue27376] Add mock_import method to mock module

2022-04-02 Thread Irit Katriel


Irit Katriel  added the comment:

Closing as that's where the discussion of 2016 was leaning. Please raise this 
on python-ideas if you would like to bring it up again.

--
nosy: +iritkatriel
resolution:  -> rejected
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
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 Israel Fruchter

Israel Fruchter added the comment:

Some real use cases is needed, like testing a code that behave differently on 
case of package availability.

I think something like patch for modules can be useful here, so you could have 
some control on what would be returned.

--
nosy: +fruch

___
Python tracker 

___
___
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 Michael Foord

Michael Foord added the comment:

Before you spend any more time on this, my current thinking is that this is a 
bit too specialised to belong in the standard library. I'll wait and see if a 
preponderance of core devs and other users disagree with me before I close this 
though.

--

___
Python tracker 

___
___
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 Michael Foord

Michael Foord added the comment:

It's not a use case I've specifically had but I can see its use. I'm uncertain 
of whether that means it belongs in the module or not. Let me see if I can get 
some more eyes on this bug.

--

___
Python tracker 

___
___
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 

___
___
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 Michael Foord

Michael Foord added the comment:

Is this for mocking out runtime dependencies that aren't available at test 
time? It seems like a good way of masking bugs! I'd be happier with a (or at 
least an option) to specify the imports that should be mocked. The use case 
should be mentioned in the docs.

I think the name is slightly confusing. I originally thought this was a 
function to mock specific imports - not to catch failed imports. 
mock_missing_import (or similar) would be a better name.

It's common with the mock functions to be able to provide a class to use as the 
mock function, and to take arbitrary keyword arguments to pass to the mock 
constructor.

--

___
Python tracker 

___
___
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 Michael Foord

Changes by Michael Foord :


--
assignee:  -> michael.foord

___
Python tracker 

___
___
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-06-23 Thread SilentGhost

Changes by SilentGhost :


--
nosy: +michael.foord
stage:  -> patch review

___
Python tracker 

___
___
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-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 

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