summaryrefslogtreecommitdiff
path: root/factory
diff options
context:
space:
mode:
authorRaphaël Barrois <raphael.barrois@polytechnique.org>2013-09-17 00:28:48 +0200
committerRaphaël Barrois <raphael.barrois@polytechnique.org>2013-09-17 00:28:54 +0200
commita8742c973db224968b74bb054027130b2ab458e0 (patch)
treee6aff374e0a4fc5f9bc9937c435bec08454f9279 /factory
parentda715e33bbba0428f0be25e8cc3ff4e88ec72bbb (diff)
downloadfactory-boy-a8742c973db224968b74bb054027130b2ab458e0.tar
factory-boy-a8742c973db224968b74bb054027130b2ab458e0.tar.gz
Add 'factory.debug' context manager.
Diffstat (limited to 'factory')
-rw-r--r--factory/__init__.py2
-rw-r--r--factory/helpers.py18
2 files changed, 20 insertions, 0 deletions
diff --git a/factory/__init__.py b/factory/__init__.py
index a27eb40..a71fea5 100644
--- a/factory/__init__.py
+++ b/factory/__init__.py
@@ -58,6 +58,8 @@ from .declarations import (
)
from .helpers import (
+ debug,
+
build,
create,
stub,
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__