def test_context_manager_false(self): """ Check that conditional manager does not enter DummyContext when condition is False """ with conditional(False, DummyContext()) as context: assert context is None
def test_context_manager_true(self): """ Check that conditional manager enters and exits DummyContext when condition is True """ with conditional(True, DummyContext()) as context: assert isinstance(context, DummyContext) assert context.enabled assert not context.enabled
def test_decorator_basic_false(self): """ Check that conditional manager decorates test_func when condition is False """ decorator = conditional(False, DummyContext()) assert not decorator.context_object.enabled @decorator def test_func(val): assert not decorator.context_object.enabled return val + 1 assert not decorator.context_object.enabled result = test_func(1) assert result == 2 assert not decorator.context_object.enabled
def test_decorator_callable_false(self): """ Check that conditional manager does not decorate test_func when condition is a callable returning False """ condition = True decorator = conditional(lambda: condition, DummyContext()) assert not decorator.context_object.enabled @decorator def test_func(val): assert not decorator.context_object.enabled return val + 1 assert not decorator.context_object.enabled condition = False result = test_func(1) assert result == 2 assert not decorator.context_object.enabled