[TIP] Fixes for mock in Python 3

Roy Williams rwilliams at lyft.com
Mon Sep 26 10:16:57 PDT 2016


Submitted http://bugs.python.org/issue28260 and the general concensious was
to only fix this in the 2.6+ backport since this isn't a problem in Python
3, and the 2.6+ version has already diverged with it's dependence on six.

On Fri, Sep 23, 2016 at 10:21 AM, Ian Cordasco <graffatcolmingov at gmail.com>
wrote:

> On Fri, Sep 23, 2016 at 12:06 PM, Roy Williams <rwilliams at lyft.com> wrote:
> > Hi all,
> >
> > I am investigating a migration to Python 3, and to facilitate this we are
> > using the -3 flag as decribed here:
> > https://docs.python.org/3/howto/pyporting.html#prevent-
> compatibility-regressions
> > . When using this flag I encountered some issues inside of mock itself.
> >
> > Python 3 now requires you to implement `__hash__` if you implement
> `__eq__`.
> > See
> > https://docs.python.org/3.6/reference/datamodel.html#
> object.%5F%5Fhash%5F%5F
> > .
> >
> > ```python
> > {mock.ANY}  # Fine in Python 2, Throws in Python 3
> > ```
> >
> > We need to explicitly sets the `__hash__` method on these objects as
> `None`
> > to ensure the behavior is consistent in Python 3 as well as Python 2.
> >
> > I've put up a PR to fix this at
> > https://github.com/testing-cabal/mock/pull/378 , but I am unsure if
> this is
> > the correct source of truth for Mock.
>
> This is the backport to Python 2.6+ from the head of Python
> development. As I understand it, patches should go to bugs.python.org
> first and then they will be backported to testing-cabal/mock on
> GitHub.
>
> Cheers,
> Ian
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20160926/99ed7a20/attachment.htm>


More information about the testing-in-python mailing list