Skip to content

itertools._tee object has no attribute error with 3.15.0 #529

@kasium

Description

@kasium

With the newest version (3.15.0) the below code fails with AttributeError: 'itertools._tee' object has no attribute 'start'

foo.py

class Client:
    def start(self):
        pass

class Lock:
    def create_client(self):
        return Client()
    def start(self):
        self._client = self.create_client()
        self._client.start()

test_foo.py

import foo

def test(mocker):
    mocker.patch("foo.Client")
    lock = foo.Lock()
    mocker.spy(lock, "create_client")
    lock.start()

The problem ist, that spy checks if the returned instance is an iterator, but each MagicMock is an iterator which leads to issues.
The logic should exclude any mock object IMO which should solve the issue

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions