Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/context_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from contextlib import contextmanager


class ClassyContextManager:
def __init__(self, thing):
self.thing = thing

def __enter__(self):
return self.thing

def __exit__(self, exc_type, exc_val, exc_tb):
pass


@contextmanager
def funky_context_manager(thing):
yield thing
15 changes: 15 additions & 0 deletions tests/test_context_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from unittest.mock import Mock

from context_manager import ClassyContextManager, funky_context_manager


def test_class_context_manager():
mock = Mock()
with ClassyContextManager(mock) as classy:
assert classy is mock


def test_funky_context_manager():
mock = Mock()
with funky_context_manager(mock) as funky:
assert funky is mock