[TIP] removing attributes and dictionary keys using mock.patch

Chris Withers chris at simplistix.co.uk
Fri Dec 5 09:01:32 PST 2014


Ease of implementation, we already have patch, patch.dict and 
patch.object, adding patch.remove, patch.dict_remove and 
patch.object_remove seems less clean to me, but I'm open to persuasion, 
especially from Michael ;-)

Chris

On 05/12/2014 16:59, Julian Berman wrote:
>
> Why not as a separate function? mock.patch(.object) are basically 
> equivalents of setattr, so if someone wants a delattr, I'd expect it 
> as a separate thing personally.
>
> -Julian
>
> On Dec 5, 2014 11:55 AM, "Chris Withers" <chris at simplistix.co.uk 
> <mailto:chris at simplistix.co.uk>> wrote:
>
>     Hi All,
>
>     I'm excited to see how far mock.patch has come, mainly as I'm
>     hoping I can deprecate testfixtures.Replacer as a result ;-)
>
>     The only think it looks like Mock can't currently do is remove
>     attributes or dictionary items:
>
>     https://pythonhosted.org/testfixtures/mocking.html#removing-attributes-and-dictionary-items
>
>     Michael, would you be up for me adding that to Mock or is it a
>     non-starter?
>
>     I'd be happy to approach using either a delete=True option to
>     patch() and patch.dict() (I don't really understand what
>     patch.object does, so can't comment...) or, alternatively, a
>     not_there or deleted marker object like I did in testfixtures.
>
>     Lemme know your thoughts...
>
>     Chris
>
>     _______________________________________________
>     testing-in-python mailing list
>     testing-in-python at lists.idyll.org
>     <mailto:testing-in-python at lists.idyll.org>
>     http://lists.idyll.org/listinfo/testing-in-python
>
>
> ______________________________________________________________________
> This email has been scanned by the Symantec Email Security.cloud service.
> For more information please visit http://www.symanteccloud.com
> ______________________________________________________________________

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20141205/4b3f560e/attachment.htm>


More information about the testing-in-python mailing list