1 file was added to this release more than 14 days after its initial publication. Inspect the release files before installing.
pytest-catchlog
py.test plugin to catch log messages. This is a fork of pytest-capturelog.
Installation
The pytest-catchlog package may be installed with pip or easy_install:
pip install pytest-catchlog easy_install pytest-catchlog
Usage
If the plugin is installed log messages are captured by default and for each failed test will be shown in the same manner as captured stdout and stderr.
Running without options:
py.test test_pytest_catchlog.py
Shows failed tests like so:
-------------------------- Captured log --------------------------- test_pytest_catchlog.py 26 INFO text going to logger ------------------------- Captured stdout ------------------------- text going to stdout ------------------------- Captured stderr ------------------------- text going to stderr ==================== 2 failed in 0.02 seconds =====================
By default each captured log message shows the module, line number, log level and message. Showing the exact module and line number is useful for testing and debugging. If desired the log format and date format can be specified to anything that the logging module supports.
Running pytest specifying formatting options:
py.test --log-format="%(asctime)s %(levelname)s %(message)s" \
--log-date-format="%Y-%m-%d %H:%M:%S" test_pytest_catchlog.py
Shows failed tests like so:
-------------------------- Captured log --------------------------- 2010-04-10 14:48:44 INFO text going to logger ------------------------- Captured stdout ------------------------- text going to stdout ------------------------- Captured stderr ------------------------- text going to stderr ==================== 2 failed in 0.02 seconds =====================
Further it is possible to disable reporting logs on failed tests completely with:
py.test --no-print-logs test_pytest_catchlog.py
Shows failed tests in the normal manner as no logs were captured:
------------------------- Captured stdout ------------------------- text going to stdout ------------------------- Captured stderr ------------------------- text going to stderr ==================== 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 caplog funcarg:
def test_foo(caplog):
caplog.setLevel(logging.INFO)
pass
By default the level is set on the handler used to catch the log 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')
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):
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'):
pass
Lastly all the logs sent to the logger during the test run are made available on the funcarg in the form of both the LogRecord instances and the final log text. This is useful for when you want to assert on the contents of a message:
def test_baz(caplog):
func_under_test()
for record in caplog.records():
assert record.levelname != 'CRITICAL'
assert 'wally' not in caplog.text()
For all the available attributes of the log records see the logging.LogRecord class.
You can also resort to record_tuples if all you want to do is to ensure, that certain messages have been logged under a given logger name with a given severity and message:
def test_foo(caplog):
logging.getLogger().info('boo %s', 'arg')
assert caplog.record_tuples() == [
('root', logging.INFO, 'boo arg'),
]
Metadata
Release files for pytest-catchlog 1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
File added late
1 file was uploaded more than 14 days after the first file in this release.
While project maintainers occasionally add legitimate files to an existing release, late additions can also indicate a security compromise.
We recommend inspecting the release files before installing.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pytest-catchlog-1.1.zip | 11.8 kB | Without provenance | Details for pytest-catchlog-1.1.zip |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pytest_catchlog-1.1-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for pytest_catchlog-1.1-py2.py3-none-any.whl |
Total release size: 19.1 kB
Release files / pytest-catchlog-1.1.zip
File added late
This file was uploaded more than 14 days after the first file in this release.
While project maintainers occasionally add legitimate files to an existing release, late additions can also indicate a security compromise.
We recommend inspecting the release file before installing.
| Download URL | pytest-catchlog-1.1.zip |
|---|---|
| Size | 11.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3b368343e9b61741f6d92bcf6c10fee340a09bca87d29218062710eda3020979
|
|
BLAKE2b-256 checksum How to use checksums |
e57b58e6213fb03ec00c73bd8b275c0ff943015b79d67ba31f4f6ee692f7167f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / pytest_catchlog-1.1-py2.py3-none-any.whl
| Download URL | pytest_catchlog-1.1-py2.py3-none-any.whl |
|---|---|
| Size | 7.3 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
b10563e0aa53ad62c44dce5742a0d15f79b54dc211f37599c16b63ed879e849a
|
|
BLAKE2b-256 checksum How to use checksums |
8e875ca52020caef2ab46cec1adb1166fc9466e3a0c08c28a1386abc057c096d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for pytest-catchlog 1.1
Upload timing
Release file added late
1 file was uploaded more than 14 days after the first file in this release.
While project maintainers occasionally add legitimate files to an existing release, late additions can also indicate a security compromise.
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.