-
Notifications
You must be signed in to change notification settings - Fork 8
Open
Description
Hi David,
is there any way to test contextmanager aware classes? Let me show you this example:
import unittest
from doublex import Spy, called, assert_that
class Context():
def __init__(self):
pass
def __enter__(self):
return self
def __exit__(self, exception_type, exception_value, exception_traceback):
pass
def execute(self):
print("foo")
context = Context()
def main(context):
with context as mycontext:
mycontext.execute()
class TestContext(unittest.TestCase):
def testing_context(self):
context = Spy()
main(context)
assert_that(context.execute, called())
if __name__ == '__main__':
unittest.main()
If you run this test, it fails. Seems as you can use doublex (Spy in this case) as context managers, you cannot spy a class using this special methods (__enter__() and __exit__()).
The line in conflict is this:
python-doublex/doublex/doubles.py
Line 65 in 6b691f5
| self._setting_up = True |
So the question... is there any way to test this? I haven't find anything related in docs.
Regards and thanks in advanced!
Metadata
Metadata
Assignees
Labels
No labels