Re: Substitute a mock object for the metaclass of a class

2017-03-13 Thread Matt Wheeler
A small correction... On Mon, 13 Mar 2017 at 22:36 Matt Wheeler wrote: > ``` > from unittest.mock import patch > > import lorem > > > @patch('lorem.type') > def test_things(mocktype): > lorem.quux(metameta.Foo()) > > lorem.return_value.assert_called_with() > this line should of course re

Re: Substitute a mock object for the metaclass of a class

2017-03-13 Thread Matt Wheeler
On Mon, 13 Mar 2017 at 00:52 Ben Finney wrote: > How can I override the metaclass of a Python class, with a > `unittest.mock.MagicMock` instance instead? > At first I misunderstood what you were looking for, and was about to reply to the effect of "you're too late, the metaclass has already been

Substitute a mock object for the metaclass of a class

2017-03-12 Thread Ben Finney
How can I override the metaclass of a Python class, with a `unittest.mock.MagicMock` instance instead? I have a function whose job involves working with the metaclass of an argument:: # lorem.py class Foo(object): pass def quux(existing_class): … metaclass =