diff options
author | Raphaël Barrois <raphael.barrois@polytechnique.org> | 2013-09-17 00:28:48 +0200 |
---|---|---|
committer | Raphaël Barrois <raphael.barrois@polytechnique.org> | 2013-09-17 00:28:54 +0200 |
commit | a8742c973db224968b74bb054027130b2ab458e0 (patch) | |
tree | e6aff374e0a4fc5f9bc9937c435bec08454f9279 /factory/helpers.py | |
parent | da715e33bbba0428f0be25e8cc3ff4e88ec72bbb (diff) | |
download | factory-boy-a8742c973db224968b74bb054027130b2ab458e0.tar factory-boy-a8742c973db224968b74bb054027130b2ab458e0.tar.gz |
Add 'factory.debug' context manager.
Diffstat (limited to 'factory/helpers.py')
-rw-r--r-- | factory/helpers.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/factory/helpers.py b/factory/helpers.py index 8f0d161..37b41bf 100644 --- a/factory/helpers.py +++ b/factory/helpers.py @@ -23,11 +23,29 @@ """Simple wrappers around Factory class definition.""" +import contextlib +import logging from . import base from . import declarations +@contextlib.contextmanager +def debug(logger='factory', stream=None): + logger_obj = logging.getLogger(logger) + old_level = logger_obj.level + + handler = logging.StreamHandler(stream) + handler.setLevel(logging.DEBUG) + logger_obj.addHandler(handler) + logger_obj.setLevel(logging.DEBUG) + + yield + + logger_obj.setLevel(old_level) + logger_obj.removeHandler(handler) + + def make_factory(klass, **kwargs): """Create a new, simple factory for the given class.""" factory_name = '%sFactory' % klass.__name__ |