[New-bugs-announce] [issue24855] fail to mock the urlopen function

sih4sing5hong5 report at bugs.python.org
Thu Aug 13 08:56:17 CEST 2015


New submission from sih4sing5hong5:

I also posted in stackoverflow: http://stackoverflow.com/questions/30978207/python-urlopen-mock-fail

```
from unittest.mock import patch
import urllib
from urllib import request
from urllib.request import urlopen

@patch('urllib.request.urlopen')
def openPatch(urlopenMock):
    print(urlopenMock)
    print(urlopen)
    print(request.urlopen)
    print(urllib.request.urlopen)

openPatch()
```
and got

```
<MagicMock name='urlopen' id='140645541554384'>
<function urlopen at 0x7fea9764c268>
<MagicMock name='urlopen' id='140645541554384'>
<MagicMock name='urlopen' id='140645541554384'>
```
request.urlopen and urllib.request.urlopen worked. Why urlopen had been not mocked?

----------
components: Library (Lib)
messages: 248500
nosy: sih4sing5hong5
priority: normal
severity: normal
status: open
title: fail to mock the urlopen function
versions: Python 3.3, Python 3.4, Python 3.5, Python 3.6

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue24855>
_______________________________________


More information about the New-bugs-announce mailing list