Anonymous avatar Anonymous committed 4504c0b

Cleaned up.

Comments (0)

Files changed (2)

pytest_capturelog.py

 import logging
 
 def pytest_addoption(parser):
+    """Adds options to py.test for controlling log capturing."""
+
     group = parser.getgroup('general')
     group.addoption('--nocapturelog',
                     dest='capturelog',
 
 
 def pytest_runtest_setup(item):
+    """Start capturing log messages for this test."""
+
     if item.config.getvalue('capturelog'):
+
+        # Create a logging handler for this test.
         item.capturelog_stream = py.io.TextIO()
         item.capturelog_handler = logging.StreamHandler(item.capturelog_stream)
         item.capturelog_formatter = logging.Formatter('%(asctime)s %(levelname)-8s: %(message)s')
         item.capturelog_handler.setFormatter(item.capturelog_formatter)
+
+        # Attach the logging handler to the root logger.
         root_logger = logging.getLogger()
         root_logger.addHandler(item.capturelog_handler)
         root_logger.setLevel(logging.NOTSET)
 
 
 def pytest_runtest_teardown(item):
+    """Stop capturing log messages for this test."""
+
     if item.config.getvalue('capturelog'):
+
+        # Detach the logging handler from the root logger.
         logging.getLogger().removeHandler(item.capturelog_handler)
 
 
 def pytest_runtest_makereport(__multicall__, item, call):
+    """Add captured log messages for this report."""
+
     report = __multicall__.execute()
 
     if item.config.getvalue('capturelog'):
+
+        # For failed tests that have captured log messages add a
+        # captured log section to the report.
         if not report.passed:
             longrepr = getattr(report, 'longrepr', None)
             if hasattr(longrepr, 'addsection'):
 import setuptools
 
 setuptools.setup(name='pytest-capturelog',
-                 version='0.1',
+                 version='0.2',
                  description='py.test plugin to capture log messages',
                  long_description=open('README').read().strip(),
                  author='Meme Dough',
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.