diff --git a/CHANGELOG b/CHANGELOG index 2aa520c4c..d24d2c02f 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -10,6 +10,8 @@ Changes between 2.2.1 and 2.2.2.dev - fix issue106: allow parametrize to be applied multiple times e.g. from module, class and at function level. - add chdir method to monkeypatch funcarg +- add "mp" funcargs as a shortcut for "monkeypatch" +- fix crash resulting from calling monkeypatch undo a second time Changes between 2.2.0 and 2.2.1 ---------------------------------------- diff --git a/_pytest/__init__.py b/_pytest/__init__.py index 842026839..0a695c203 100644 --- a/_pytest/__init__.py +++ b/_pytest/__init__.py @@ -1,2 +1,2 @@ # -__version__ = '2.2.2.dev5' +__version__ = '2.2.2.dev6' diff --git a/doc/monkeypatch.txt b/doc/monkeypatch.txt index 8c5818c23..1f9090ce4 100644 --- a/doc/monkeypatch.txt +++ b/doc/monkeypatch.txt @@ -14,14 +14,14 @@ and a discussion of its motivation. .. _`monkeypatch blog post`: http://tetamap.wordpress.com/2009/03/03/monkeypatching-in-unit-tests-done-right/ - -Simple example: patching ``os.path.expanduser`` +Simple example: monkeypatching functions --------------------------------------------------- -If, for instance, you want to pretend that ``os.expanduser`` returns a certain +If you want to pretend that ``os.expanduser`` returns a certain directory, you can use the :py:meth:`monkeypatch.setattr` method to patch this function before calling into a function which uses it:: + # content of test_module.py import os.path def getssh(): # pseudo application code return os.path.join(os.path.expanduser("~admin"), '.ssh') @@ -33,22 +33,20 @@ patch this function before calling into a function which uses it:: x = getssh() assert x == '/abc/.ssh' -After the test function finishes the ``os.path.expanduser`` modification -will be undone. +Here our test function monkeypatches ``os.path.expanduser`` and +then calls into an function that calls it. After the test function +finishes the ``os.path.expanduser`` modification will be undone. -.. background check: - $ py.test - =========================== test session starts ============================ - platform darwin -- Python 2.7.1 -- pytest-2.2.1 - collecting ... collected 0 items - - ============================= in 0.00 seconds ============================= +.. note:: + + As with version 2.2.2 there is a ``mp`` function argument + which is a shortcut for "monkeypatch". Method reference of the monkeypatch function argument ----------------------------------------------------- .. autoclass:: monkeypatch - :members: setattr, delattr, setitem, delitem, setenv, delenv, syspath_prepend, undo + :members: setattr, delattr, setitem, delitem, setenv, delenv, syspath_prepend, chdir, undo ``monkeypatch.setattr/delattr/delitem/delenv()`` all by default raise an Exception if the target does not exist. diff --git a/setup.py b/setup.py index b19ea6064..e28c8af9f 100644 --- a/setup.py +++ b/setup.py @@ -24,7 +24,7 @@ def main(): name='pytest', description='py.test: simple powerful testing with Python', long_description = long_description, - version='2.2.2.dev5', + version='2.2.2.dev6', url='http://pytest.org', license='MIT license', platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'],