[TIP] Problem with mock

Ken Hagler khagler at orange-road.com
Thu Dec 20 11:31:45 PST 2012

On Dec 20, 2012, at 9:01 AM, Julian Berman <julian at grayvines.com> wrote:

> You need to replace in the module under test (can't link to the docs but
> there's a helpful article there if you can't figure it out).
> Something like:
> with mock.patch("mymodule.super", create=True) as mock_super:
>    mock_super.return_value.config.whatever = 12
>     exercise()
>     assert()

Okay I tried this, so now test_init starts:

with patch('DevBuild.super', create=True) as mock_super:
            mock_MakeDevBuild = MagicMock()
            mock_super.return_value.config.MakeDevBuild = mock_MakeDevBuild

This is certainly simpler, but it also produces the same error: "AttributeError: 'DevBuild' object has no attribute 'config'"
                              Ken Hagler

|                   http://www.orange-road.com/                   |
|   And tho' we are not now that strength which in old days       |
|   Moved earth and heaven, that which we are, we are --Tennyson  |

More information about the testing-in-python mailing list