Skip to content

Commit 498cd51

Browse files
authored
Merge pull request #66 from pokidovea/master
Added "mock.mock_open" to the "mocker" fixture for convenience.
2 parents 931785c + 948d975 commit 498cd51

File tree

4 files changed

+11
-3
lines changed

4 files changed

+11
-3
lines changed

CHANGELOG.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@
33

44
* Add support for Python 3.6. Thanks `@hackebrot`_ for the report (`#59`_).
55

6+
* ``mock.mock_open`` is now aliased as ``mocker.mock_open`` for convenience.
7+
Thanks `@pokidovea`_ for the PR (`#66`_).
8+
69
.. _@hackebrot: https://github.com/hackebrot
10+
.. _@pokidovea: https://github.com/pokidovea
711
.. _#59: https://github.com/pytest-dev/pytest-mock/issues/59
12+
.. _#66: https://github.com/pytest-dev/pytest-mock/pull/66
813

914
1.2
1015
---

README.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ The supported methods are:
6060
* ``mocker.patch.multiple``: see http://www.voidspace.org.uk/python/mock/patch.html#patch-multiple.
6161
* ``mocker.patch.dict``: see http://www.voidspace.org.uk/python/mock/patch.html#patch-dict.
6262
* ``mocker.stopall()``: stops all active patches up to this point.
63-
* ``mocker.resetall()``: calls ``reset_mock()`` in all mocked objects up to this point.
63+
* ``mocker.resetall()``: calls ``reset_mock()`` in all mocked objects up to this point.
6464

6565
Some objects from the ``mock`` module are accessible directly from ``mocker`` for convenience:
6666

@@ -70,6 +70,7 @@ Some objects from the ``mock`` module are accessible directly from ``mocker`` fo
7070
* `ANY <https://docs.python.org/3/library/unittest.mock.html#any>`_
7171
* `call <https://docs.python.org/3/library/unittest.mock.html#call>`_ *(Version 1.1)*
7272
* `sentinel <https://docs.python.org/3/library/unittest.mock.html#sentinel>`_ *(Version 1.2)*
73+
* `mock_open <https://docs.python.org/3/library/unittest.mock.html#mock-open>`_
7374

7475

7576
Spy

pytest_mock.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ class MockFixture(object):
2121
PropertyMock = mock_module.PropertyMock
2222
call = mock_module.call
2323
ANY = mock_module.ANY
24-
24+
sentinel = mock_module.sentinel
25+
mock_open = mock_module.mock_open
2526

2627
def __init__(self):
2728
self._patches = [] # list of mock._patch objects
@@ -30,6 +31,7 @@ def __init__(self):
3031
# temporary fix: this should be at class level, but is blowing
3132
# up in Python 3.6
3233
self.sentinel = mock_module.sentinel
34+
self.mock_open = mock_module.mock_open
3335

3436
def resetall(self):
3537
"""

test_pytest_mock.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def test_deprecated_mock(mock, tmpdir):
132132
assert os.listdir(str(tmpdir)) == []
133133

134134

135-
@pytest.mark.parametrize('name', ['MagicMock', 'PropertyMock', 'Mock', 'call', 'ANY', 'sentinel'])
135+
@pytest.mark.parametrize('name', ['MagicMock', 'PropertyMock', 'Mock', 'call', 'ANY', 'sentinel', 'mock_open'])
136136
def test_mocker_aliases(name):
137137
from pytest_mock import mock_module, MockFixture
138138

0 commit comments

Comments
 (0)