Commits

Anonymous committed 27a53ff

Make consistent with rest of code. Added caplog as new name for funcarg.

  • Participants
  • Parent commits 9eab019
  • Tags RELEASE_0_7

Comments (0)

Files changed (4)

     ==================== 2 failed in 0.02 seconds =====================
 
 Inside tests it is possible to change the log level for the captured
-log messages.  This is supported by the ``capturelog`` funcarg::
+log messages.  This is supported by the ``caplog`` funcarg::
 
-    def test_foo(capturelog):
-        capturelog.setLevel(logging.INFO)
+    def test_foo(caplog):
+        caplog.setLevel(logging.INFO)
         pass
 
 By default the level is set on the handler used to capture the log
 messages, however as a convenience it is also possible to set the log
 level of any logger::
 
-    def test_foo(capturelog):
-        capturelog.setLevel(logging.CRITICAL, logger='root.baz')
+    def test_foo(caplog):
+        caplog.setLevel(logging.CRITICAL, logger='root.baz')
         pass
 
 It is also possible to use a context manager to temporarily change the
 log level::
 
-    def test_bar(capturelog):
-        with capturelog.atLevel(logging.INFO):
+    def test_bar(caplog):
+        with caplog.atLevel(logging.INFO):
             pass
 
 Again, by default the level of the handler is affected but the level
 of any logger can be changed instead with::
 
-    def test_bar(capturelog):
-        with capturelog.atLevel(logging.CRITICAL, logger='root.baz'):
+    def test_bar(caplog):
+        with caplog.atLevel(logging.CRITICAL, logger='root.baz'):
             pass
 
 Lastly all the logs sent to the logger during the test run are made
 and the final log text.  This is useful for when you want to assert on
 the contents of a message::
 
-    def test_baz(capturelog):
+    def test_baz(caplog):
         func_under_test()
-        for record in capturelog.records():
+        for record in caplog.records():
             assert record.levelname != 'CRITICAL'
-        assert 'wally' not in capturelog.text()
+        assert 'wally' not in caplog.text()
 
 For all the available attributes of the log records see the
 ``logging.LogRecord`` class.

File pytest_capturelog.py

     ==================== 2 failed in 0.02 seconds =====================
 
 Inside tests it is possible to change the log level for the captured
-log messages.  This is supported by the ``capturelog`` funcarg::
+log messages.  This is supported by the ``caplog`` funcarg::
 
-    def test_foo(capturelog):
-        capturelog.setLevel(logging.INFO)
+    def test_foo(caplog):
+        caplog.setLevel(logging.INFO)
         pass
 
 By default the level is set on the handler used to capture the log
 messages, however as a convenience it is also possible to set the log
 level of any logger::
 
-    def test_foo(capturelog):
-        capturelog.setLevel(logging.CRITICAL, logger='root.baz')
+    def test_foo(caplog):
+        caplog.setLevel(logging.CRITICAL, logger='root.baz')
         pass
 
 It is also possible to use a context manager to temporarily change the
 log level::
 
-    def test_bar(capturelog):
-        with capturelog.atLevel(logging.INFO):
+    def test_bar(caplog):
+        with caplog.atLevel(logging.INFO):
             pass
 
 Again, by default the level of the handler is affected but the level
 of any logger can be changed instead with::
 
-    def test_bar(capturelog):
-        with capturelog.atLevel(logging.CRITICAL, logger='root.baz'):
+    def test_bar(caplog):
+        with caplog.atLevel(logging.CRITICAL, logger='root.baz'):
             pass
 
 Lastly all the logs sent to the logger during the test run are made
 and the final log text.  This is useful for when you want to assert on
 the contents of a message::
 
-    def test_baz(capturelog):
+    def test_baz(caplog):
         func_under_test()
-        for record in capturelog.records():
+        for record in caplog.records():
             assert record.levelname != 'CRITICAL'
-        assert 'wally' not in capturelog.text()
+        assert 'wally' not in caplog.text()
 
 For all the available attributes of the log records see the
 ``logging.LogRecord`` class.
 
         return report
 
-def pytest_funcarg__capturelog(request):
-    """Returns a funcarg to access and control log capturing."""
-    return CaptureLogFuncArg(request._pyfuncitem.capturelog_handler)
-
 
 class CaptureLogHandler(logging.StreamHandler):
     """A logging handler that stores log records and the log text."""
         """Restore the log level."""
 
         self.obj.setLevel(self.orig_level)
+
+
+def pytest_funcarg__caplog(request):
+    """Returns a funcarg to access and control log capturing."""
+
+    return CaptureLogFuncArg(request._pyfuncitem.capturelog_handler)
+
+
+def pytest_funcarg__capturelog(request):
+    """Returns a funcarg to access and control log capturing."""
+
+    return CaptureLogFuncArg(request._pyfuncitem.capturelog_handler)
 import setuptools
 
 setuptools.setup(name='pytest-capturelog',
-                 version='0.6',
+                 version='0.7',
                  description='py.test plugin to capture log messages',
                  long_description=open('README').read().strip(),
                  author='Meme Dough',

File test_pytest_capturelog.py

 
         pytest_plugins = 'capturelog'
 
-        def test_foo(capturelog):
-            capturelog.setLevel(logging.INFO)
+        def test_foo(caplog):
+            caplog.setLevel(logging.INFO)
             log = logging.getLogger()
             log.debug('handler DEBUG level')
             log.info('handler INFO level')
 
-            capturelog.setLevel(logging.CRITICAL, logger='root.baz')
+            caplog.setLevel(logging.CRITICAL, logger='root.baz')
             log = logging.getLogger('root.baz')
             log.warning('logger WARNING level')
             log.critical('logger CRITICAL level')
 
         pytest_plugins = 'capturelog'
 
-        def test_foo(capturelog):
-            with capturelog.atLevel(logging.INFO):
+        def test_foo(caplog):
+            with caplog.atLevel(logging.INFO):
                 log = logging.getLogger()
                 log.debug('handler DEBUG level')
                 log.info('handler INFO level')
 
-                with capturelog.atLevel(logging.CRITICAL, logger='root.baz'):
+                with caplog.atLevel(logging.CRITICAL, logger='root.baz'):
                     log = logging.getLogger('root.baz')
                     log.warning('logger WARNING level')
                     log.critical('logger CRITICAL level')
 
         pytest_plugins = 'capturelog'
 
-        def test_foo(capturelog):
+        def test_foo(caplog):
             logging.getLogger().info('boo %s', 'arg')
-            assert capturelog.records()[0].levelname == 'INFO'
-            assert capturelog.records()[0].msg == 'boo %s'
-            assert 'boo arg' in capturelog.text()
+            assert caplog.records()[0].levelname == 'INFO'
+            assert caplog.records()[0].msg == 'boo %s'
+            assert 'boo arg' in caplog.text()
         ''')
     result = testdir.runpytest()
     assert result.ret == 0
 
 def test_funcarg_help(testdir):
-    result = testdir.runpytest("--funcargs")
-    result.stdout.fnmatch_lines([
-        "*capturelog*",
-    ])
+    result = testdir.runpytest('--funcargs')
+    result.stdout.fnmatch_lines(['*caplog*'])