Changes¶
1.5.3¶
- release-date
2017-02-22 03:26 p.m PST
- release-by
Ask Solem
patch.multiple
now works.
1.5.2¶
- release-date
2016-10-28 03:40 p.m. PDT
- release-by
Ask Solem
Using setup/teardown instead of setup_method/teardown_method was a bad idea.
Since it’s way more common to override setup/teardown, and it’s likely people forget to call super in these methods, the change crashed several test suites.
So on pytest the decorators are now back to augmenting setup_method/teardown_method again.
1.5.1¶
- release-date
2016-10-28 03:40 p.m. PDT
- release-by
Ask Solem
1.5.0 had a left over print statement :blush:
1.5.0¶
- release-date
2016-10-28 03:36 p.m. PDT
- release-by
Ask Solem
Pytest: When decorating classes using the
skip.*
andmock.*
decorators, these now augmentcls.setup
/cls.teardown
instead ofcls.setup_method
/cls.teardown_method
.It’s a bit hard to find in the pytest documentation, but pytest will always call test_cls.setup and test_cls.teardown.
Pytest: Adds
patching.object
.This works exactly like
unittest.mock.patch.object()
, you give it an object and an attribute name, and it will patch that attribute on the object. It also supports the same arguments and extra options.Example:
@pytest.fixture def channel(patching): c = Channel() patching(c, 'connect') return c
1.4.0¶
- release-date
2016-10-17 06:14 p.m. PDT
- release-by
Ask Solem
Adds new helper:
case.pytest.fixture_with_options
.Example:
@fixture_with_options() def sftp(request, username='test_username', password='test_password'): return {'username': username, 'password': password} @sftp.options(username='foo', password='bar') def test_foo(sftp): assert sftp['username'] == 'foo' assert sftp['password'] == 'bar'
1.3.1¶
- release-date
2016-07-22 06:14 p.m. PDT
- release-by
Ask Solem
All case decorators now works with py.test classes.
Py.test: Adds new stdouts fixture that patches
sys.stdout
, andsys.stderr
.Example:
def test_x(stdouts): print('foo') assert 'foo' in stdouts.stdout.getvalue() print('bar', file=sys.stderr) assert 'bar' in stdouts.stderr.getvalue()
Py.test: The patching fixture can now mock modules.
Example:
def test_x(patching): gevent, gevent_monkey = patching.modules( 'gevent', 'gevent.monkey', ) os = patching.modules('os') gevent_monkey.patch_all.side_effect = RuntimeError() with pytest.raises(RuntimeError): from gevent import monkey monkey.patch_all()
1.3.0¶
- release-date
2016-07-18 05:33 p.m. PDT
- release-by
Ask Solem
Case is now a py.test plug-in and provides a patching fixture as a shortcut to monkeypatch setting the value to a mock.
This does not have any effects for users not using py.test.
Example:
def test_foo(patching): # execv value here will be mock.MagicMock by default. execv = patching('os.execv') patching('sys.platform', 'darwin') # set concrete value patching.setenv('DJANGO_SETTINGS_MODULE', 'x.settings') # val will be of type mock.MagicMock by default val = patching.setitem('path.to.dict', 'KEY')
1.2.3¶
- release-date
2016-06-15 03:00 p.m. PDT
- release-by
Ask Solem
Case decorators now supports py.test.
Patcher created by create_patcher now accepts *args.
1.2.2¶
- release-date
2016-06-23 02:46 p.m. PDT
- release-by
Ask Solem
mock.reload_modules
: Fixed compatibility with Python 3.
1.2.1¶
- release-date
2016-06-23 12:111 p.m. PDT
- release-by
Ask Solem
mock.reload_modules
now re-imports the module and callsreload()
on it.This fixes issues with side effects not being properly reset after context exits.
1.2.0¶
- release-date
2016-06-13 05:00 p.m. PDT
- release-by
Ask Solem
Adds
mock.mute
decorator to suppress stdout with no return value.Contributed by Tony Narlock.
Adds
Mock.on_nth_call_do_raise(excA, excB, n)
.This will make the mock raise excA until called n times, in which it will start to raise excB.
1.1.4¶
- release-date
2016-05-12 03:04 p.m. PDT
- release-by
Ask Solem
case.patch.*
functions now supports usingnew
as a positional argument, for compatibility withmock.patch
.
1.1.3¶
- release-date
2016-04-19 04:41 p.m. PDT
- release-by
Ask Solem
case.patch(autospec=True)
now works.This will use the original mock.MagicMock, not case.MagicMock.
1.1.2¶
- release-date
2016-04-08 11:34 p.m. PDT
- release-by
Ask Solem
Also
case.patch.multiple()
, andcase.patch.object()
now givescase.MagicMock
.
1.1.1¶
- release-date
2016-04-08 11:13 p.m. PDT
- release-by
Ask Solem
case.patch()
now givescase.MagicMock
(notmock.MagicMock
).
1.1.0¶
- release-date
2016-04-08 10:00 p.m. PDT
- release-by
Ask Solem
Adds new Mock methods from Python 3.6:
Mock.assert_called()
Mock.assert_not_called()
Mock.assert_called_once()
Adds
Mock.create_patcher()
Example:
from case import Case, mock patch_commands = mock.create_patcher('long_name.management.commands') class test_FooCommand(Case): @patch_commands('FooCommand.authenticate') def test_foo(self, authenticate): pass
1.0.3¶
- release-date
2016-04-06 04:00 p.m. PDT
- release-by
Ask Solem
Python 2.6 compatibility.
mock.platform_pyimp
no longer accepted default value.
1.0.2¶
- release-date
2016-04-06 03:46 p.m. PDT
- release-by
Ask Solem
Adds docstrings
1.0.1¶
- release-date
2016-04-05 04:00 p.m. PDT
- release-by
Ask Solem
Fixed issues with Python 3
1.0.0¶
- release-date
2016-04-05 02:00 p.m. PDT
- release-by
Ask Solem
Initial release