Skip to content

Doubles and contextlib #118

@markuswustenberg

Description

@markuswustenberg

I'm trying to use doubles with a class that uses the @contextmanager decorator on a method: https://docs.python.org/2/library/contextlib.html

However, this fails because __enter__ and __exit__ are not properly handled on the double. Any way to add this functionality to doubles? Or am I holding it wrong?

I would expect something like this to work:

from contextlib import contextmanager
from doubles import expect, ObjectDouble

class Stats(object):
    @contextmanager
    def timed(self, key):
        pass

def test__timed_does_stuff():
    d = ObjectDouble(Stats())
    expect(d).timed.once()
    with d.timed('mykey'):
        pass

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions