Skip to content

Commit

Permalink
Merge pull request #66 from pokidovea/master
Browse files Browse the repository at this point in the history
Added "mock.mock_open" to the "mocker" fixture for convenience.
  • Loading branch information
nicoddemus authored Oct 29, 2016
2 parents 931785c + 948d975 commit 498cd51
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@

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

* ``mock.mock_open`` is now aliased as ``mocker.mock_open`` for convenience.
Thanks `@pokidovea`_ for the PR (`#66`_).

.. _@hackebrot: https://github.com/hackebrot
.. _@pokidovea: https://github.com/pokidovea
.. _#59: https://github.com/pytest-dev/pytest-mock/issues/59
.. _#66: https://github.com/pytest-dev/pytest-mock/pull/66

1.2
---
Expand Down
3 changes: 2 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ The supported methods are:
* ``mocker.patch.multiple``: see http://www.voidspace.org.uk/python/mock/patch.html#patch-multiple.
* ``mocker.patch.dict``: see http://www.voidspace.org.uk/python/mock/patch.html#patch-dict.
* ``mocker.stopall()``: stops all active patches up to this point.
* ``mocker.resetall()``: calls ``reset_mock()`` in all mocked objects up to this point.
* ``mocker.resetall()``: calls ``reset_mock()`` in all mocked objects up to this point.

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

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


Spy
Expand Down
4 changes: 3 additions & 1 deletion pytest_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class MockFixture(object):
PropertyMock = mock_module.PropertyMock
call = mock_module.call
ANY = mock_module.ANY

sentinel = mock_module.sentinel
mock_open = mock_module.mock_open

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

def resetall(self):
"""
Expand Down
2 changes: 1 addition & 1 deletion test_pytest_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def test_deprecated_mock(mock, tmpdir):
assert os.listdir(str(tmpdir)) == []


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

Expand Down

0 comments on commit 498cd51

Please sign in to comment.