summaryrefslogtreecommitdiff
path: root/README.rst
diff options
context:
space:
mode:
Diffstat (limited to 'README.rst')
-rw-r--r--README.rst42
1 files changed, 27 insertions, 15 deletions
diff --git a/README.rst b/README.rst
index 2287412..bc7fcba 100644
--- a/README.rst
+++ b/README.rst
@@ -30,11 +30,11 @@ Running without options::
Shows failed tests like so::
- -------------------------- Captured log ---------------------------
+ ----------------------- Captured stdlog call ----------------------
test_pytest_catchlog.py 26 INFO text going to logger
- ------------------------- Captured stdout -------------------------
+ ----------------------- Captured stdout call ----------------------
text going to stdout
- ------------------------- Captured stderr -------------------------
+ ----------------------- Captured stderr call ----------------------
text going to stderr
==================== 2 failed in 0.02 seconds =====================
@@ -50,14 +50,26 @@ Running pytest specifying formatting options::
Shows failed tests like so::
- -------------------------- Captured log ---------------------------
+ ----------------------- Captured stdlog call ----------------------
2010-04-10 14:48:44 INFO text going to logger
- ------------------------- Captured stdout -------------------------
+ ----------------------- Captured stdout call ----------------------
text going to stdout
- ------------------------- Captured stderr -------------------------
+ ----------------------- Captured stderr call ----------------------
text going to stderr
==================== 2 failed in 0.02 seconds =====================
+These options can also be customized through a configuration file::
+
+ [pytest]
+ log_format = %(asctime)s %(levelname)s %(message)s
+ log_date_format = %Y-%m-%d %H:%M:%S
+
+Although the same effect could be achieved through the ``addopts`` setting,
+using dedicated options should be preferred since the latter doesn't
+force other developers to have ``pytest-catchlog`` installed (while at
+the same time, ``addopts`` approach would fail with 'unrecognized arguments'
+error). Command line arguments take precedence.
+
Further it is possible to disable reporting logs on failed tests
completely with::
@@ -65,9 +77,9 @@ completely with::
Shows failed tests in the normal manner as no logs were captured::
- ------------------------- Captured stdout -------------------------
+ ----------------------- Captured stdout call ----------------------
text going to stdout
- ------------------------- Captured stderr -------------------------
+ ----------------------- Captured stderr call ----------------------
text going to stderr
==================== 2 failed in 0.02 seconds =====================
@@ -75,7 +87,7 @@ Inside tests it is possible to change the log level for the captured
log messages. This is supported by the ``caplog`` funcarg::
def test_foo(caplog):
- caplog.setLevel(logging.INFO)
+ caplog.set_level(logging.INFO)
pass
By default the level is set on the handler used to catch the log
@@ -83,21 +95,21 @@ messages, however as a convenience it is also possible to set the log
level of any logger::
def test_foo(caplog):
- caplog.setLevel(logging.CRITICAL, logger='root.baz')
+ caplog.set_level(logging.CRITICAL, logger='root.baz')
pass
It is also possible to use a context manager to temporarily change the
log level::
def test_bar(caplog):
- with caplog.atLevel(logging.INFO):
+ with caplog.at_level(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(caplog):
- with caplog.atLevel(logging.CRITICAL, logger='root.baz'):
+ with caplog.at_level(logging.CRITICAL, logger='root.baz'):
pass
Lastly all the logs sent to the logger during the test run are made
@@ -107,9 +119,9 @@ the contents of a message::
def test_baz(caplog):
func_under_test()
- for record in caplog.records():
+ for record in caplog.records:
assert record.levelname != 'CRITICAL'
- assert 'wally' not in caplog.text()
+ assert 'wally' not in caplog.text
For all the available attributes of the log records see the
``logging.LogRecord`` class.
@@ -121,7 +133,7 @@ given severity and message::
def test_foo(caplog):
logging.getLogger().info('boo %s', 'arg')
- assert caplog.record_tuples() == [
+ assert caplog.record_tuples == [
('root', logging.INFO, 'boo arg'),
]