[New-bugs-announce] [issue39966] mock 3.9 bug: Wrapped objects without __bool__ raise exception

Avram report at bugs.python.org
Sun Mar 15 02:39:44 EDT 2020


New submission from Avram <python at avram.us>:

This bug was introduced with Issue25597


Here's some code that demonstrates the error:

    import sys
    from unittest.mock import patch

    with patch.object(sys, 'stdout', wraps=sys.stdout) as mockstdout:
        bool(sys.stdout)

This works fine in 3.8 and earlier, but fails in 3.9

It seems the goal was to be able to access dunder methods for wrapped objects. Before this change __bool__ wasn't actually being checked, but was forced to True, which works for basic existence tests. The new code method._mock_wraps = getattr(mock._mock_wraps, name) has no fallthrough in case the attribute isn't there such as the case with __bool__ on sys.stdout.

----------
components: Library (Lib)
messages: 364222
nosy: Darragh Bailey, anthonypjshaw, aviso, cjw296, lisroach, mariocj89, michael.foord, pconnell, r.david.murray, rbcollins, xtreak
priority: normal
severity: normal
status: open
title: mock 3.9 bug: Wrapped objects without __bool__ raise exception
type: behavior
versions: Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue39966>
_______________________________________


More information about the New-bugs-announce mailing list