pytest-loguru 0.4.0__tar.gz → 0.4.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pytest_loguru-0.4.0 → pytest_loguru-0.4.2}/.github/dependabot.yaml +12 -0
- pytest_loguru-0.4.2/.github/workflows/publish.yaml +42 -0
- pytest_loguru-0.4.2/.github/workflows/run-python-tests.yaml +67 -0
- {pytest_loguru-0.4.0 → pytest_loguru-0.4.2}/.gitignore +43 -3
- pytest_loguru-0.4.2/.pre-commit-config.yaml +25 -0
- pytest_loguru-0.4.2/.python-version +1 -0
- pytest_loguru-0.4.2/CLAUDE.md +72 -0
- pytest_loguru-0.4.2/CONTRIBUTING.md +9 -0
- pytest_loguru-0.4.2/PKG-INFO +160 -0
- pytest_loguru-0.4.2/README.md +125 -0
- pytest_loguru-0.4.2/pyproject.toml +148 -0
- pytest_loguru-0.4.2/src/pytest_loguru/__init__.py +3 -0
- pytest_loguru-0.4.2/src/pytest_loguru/_version.py +24 -0
- pytest_loguru-0.4.2/src/pytest_loguru/plugin.py +78 -0
- pytest_loguru-0.4.2/src/pytest_loguru/py.typed +0 -0
- pytest_loguru-0.4.2/tests/pytest_loguru/test_plugin.py +226 -0
- pytest_loguru-0.4.2/uv.lock +962 -0
- pytest_loguru-0.4.0/.config/coveragerc +0 -17
- pytest_loguru-0.4.0/.config/pre-commit-config.yaml +0 -25
- pytest_loguru-0.4.0/.config/pytest.ini +0 -4
- pytest_loguru-0.4.0/.config/ruff.toml +0 -16
- pytest_loguru-0.4.0/.github/workflows/publish.yml +0 -33
- pytest_loguru-0.4.0/.github/workflows/run-python-tests.yml +0 -48
- pytest_loguru-0.4.0/CONTRIBUTING.md +0 -55
- pytest_loguru-0.4.0/PKG-INFO +0 -54
- pytest_loguru-0.4.0/README.md +0 -20
- pytest_loguru-0.4.0/pyproject.toml +0 -94
- pytest_loguru-0.4.0/requirements.txt +0 -16
- pytest_loguru-0.4.0/src/pytest_loguru/__init__.py +0 -1
- pytest_loguru-0.4.0/src/pytest_loguru/_version.py +0 -16
- pytest_loguru-0.4.0/src/pytest_loguru/plugin.py +0 -28
- pytest_loguru-0.4.0/tests/pytest_loguru/test_plugin.py +0 -27
- {pytest_loguru-0.4.0 → pytest_loguru-0.4.2}/LICENSE +0 -0
|
@@ -10,3 +10,15 @@ updates:
|
|
|
10
10
|
schedule:
|
|
11
11
|
# Check for updates to GitHub Actions every week
|
|
12
12
|
interval: "weekly"
|
|
13
|
+
|
|
14
|
+
- package-ecosystem: "uv"
|
|
15
|
+
directory: "/"
|
|
16
|
+
schedule:
|
|
17
|
+
# Check for updates to Python dependencies in uv.lock every week
|
|
18
|
+
interval: "weekly"
|
|
19
|
+
|
|
20
|
+
- package-ecosystem: "pre-commit"
|
|
21
|
+
directory: "/"
|
|
22
|
+
schedule:
|
|
23
|
+
# Check for updates to hook revs in .pre-commit-config.yaml every week
|
|
24
|
+
interval: "weekly"
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [published]
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
test:
|
|
9
|
+
uses: ./.github/workflows/run-python-tests.yaml
|
|
10
|
+
permissions:
|
|
11
|
+
contents: read
|
|
12
|
+
checks: write
|
|
13
|
+
pull-requests: write
|
|
14
|
+
|
|
15
|
+
publish:
|
|
16
|
+
needs: test
|
|
17
|
+
runs-on: ubuntu-latest
|
|
18
|
+
|
|
19
|
+
environment:
|
|
20
|
+
name: pypi
|
|
21
|
+
url: https://pypi.org/p/pytest-loguru
|
|
22
|
+
|
|
23
|
+
permissions:
|
|
24
|
+
id-token: write
|
|
25
|
+
contents: read
|
|
26
|
+
|
|
27
|
+
steps:
|
|
28
|
+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
29
|
+
|
|
30
|
+
- name: Get history and tags for versioning to work
|
|
31
|
+
run: |
|
|
32
|
+
git fetch --prune --unshallow
|
|
33
|
+
git fetch --depth=1 origin +refs/tags/*:refs/tags/*
|
|
34
|
+
|
|
35
|
+
- name: Install uv
|
|
36
|
+
uses: astral-sh/setup-uv@bec219d24cd3e171d82865faccec33120bb574f4 # v10.1.0
|
|
37
|
+
|
|
38
|
+
- name: Build with uv
|
|
39
|
+
run: uv build
|
|
40
|
+
|
|
41
|
+
- name: Publish distribution to PyPI
|
|
42
|
+
run: uv publish
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
name: Run tests
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
workflow_dispatch:
|
|
5
|
+
# Called by publish.yaml so a release only publishes after the tests pass.
|
|
6
|
+
workflow_call:
|
|
7
|
+
push:
|
|
8
|
+
branches-ignore: [gh-pages, "dependabot/**"]
|
|
9
|
+
pull_request:
|
|
10
|
+
branches-ignore: [gh-pages]
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
build:
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
permissions:
|
|
16
|
+
contents: read
|
|
17
|
+
checks: write
|
|
18
|
+
pull-requests: write
|
|
19
|
+
|
|
20
|
+
strategy:
|
|
21
|
+
fail-fast: false
|
|
22
|
+
matrix:
|
|
23
|
+
# Keep in sync with requires-python and the classifiers in
|
|
24
|
+
# pyproject.toml. The default in .python-version runs lint and
|
|
25
|
+
# publishes the reports.
|
|
26
|
+
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]
|
|
27
|
+
|
|
28
|
+
name: build (Python ${{ matrix.python-version }})
|
|
29
|
+
|
|
30
|
+
steps:
|
|
31
|
+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
32
|
+
|
|
33
|
+
- name: Install uv
|
|
34
|
+
uses: astral-sh/setup-uv@bec219d24cd3e171d82865faccec33120bb574f4 # v10.1.0
|
|
35
|
+
with:
|
|
36
|
+
enable-cache: true
|
|
37
|
+
python-version: ${{ matrix.python-version }}
|
|
38
|
+
|
|
39
|
+
- name: Install dependencies
|
|
40
|
+
run: uv sync --frozen
|
|
41
|
+
|
|
42
|
+
- name: Run pre-commit
|
|
43
|
+
if: matrix.python-version == '3.12'
|
|
44
|
+
run: uvx pre-commit run --all-files --show-diff-on-failure
|
|
45
|
+
|
|
46
|
+
- name: Test with pytest
|
|
47
|
+
run: uv run coverage run -m pytest
|
|
48
|
+
|
|
49
|
+
# lcov before report, so Coveralls still gets data when coverage is
|
|
50
|
+
# below fail_under and `coverage report` fails the job.
|
|
51
|
+
- name: Check coverage
|
|
52
|
+
run: |
|
|
53
|
+
uv run coverage lcov
|
|
54
|
+
uv run coverage report
|
|
55
|
+
|
|
56
|
+
- name: Publish Unit Test Results
|
|
57
|
+
uses: EnricoMi/publish-unit-test-result-action@d0a4676d0e0b938bc201470d88276b7c74c712b3 # v2.24.0
|
|
58
|
+
if: always() && matrix.python-version == '3.12'
|
|
59
|
+
with:
|
|
60
|
+
files: test-results.xml
|
|
61
|
+
|
|
62
|
+
- name: Publish in Coveralls
|
|
63
|
+
uses: coverallsapp/github-action@8d6379e14d29928660c4ba802d8e85393440b329 # v2.3.8
|
|
64
|
+
if: always() && matrix.python-version == '3.12'
|
|
65
|
+
with:
|
|
66
|
+
flag-name: tests
|
|
67
|
+
format: lcov
|
|
@@ -20,7 +20,6 @@ parts/
|
|
|
20
20
|
sdist/
|
|
21
21
|
var/
|
|
22
22
|
wheels/
|
|
23
|
-
pip-wheel-metadata/
|
|
24
23
|
share/python-wheels/
|
|
25
24
|
*.egg-info/
|
|
26
25
|
.installed.cfg
|
|
@@ -50,6 +49,9 @@ coverage.xml
|
|
|
50
49
|
*.py,cover
|
|
51
50
|
.hypothesis/
|
|
52
51
|
.pytest_cache/
|
|
52
|
+
cover/
|
|
53
|
+
coverage.lcov
|
|
54
|
+
test-results.xml
|
|
53
55
|
|
|
54
56
|
# Translations
|
|
55
57
|
*.mo
|
|
@@ -72,6 +74,7 @@ instance/
|
|
|
72
74
|
docs/_build/
|
|
73
75
|
|
|
74
76
|
# PyBuilder
|
|
77
|
+
.pybuilder/
|
|
75
78
|
target/
|
|
76
79
|
|
|
77
80
|
# Jupyter Notebook
|
|
@@ -82,7 +85,9 @@ profile_default/
|
|
|
82
85
|
ipython_config.py
|
|
83
86
|
|
|
84
87
|
# pyenv
|
|
85
|
-
|
|
88
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
89
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
90
|
+
# .python-version
|
|
86
91
|
|
|
87
92
|
# pipenv
|
|
88
93
|
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
@@ -91,7 +96,22 @@ ipython_config.py
|
|
|
91
96
|
# install all needed dependencies.
|
|
92
97
|
#Pipfile.lock
|
|
93
98
|
|
|
94
|
-
#
|
|
99
|
+
# poetry
|
|
100
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
101
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
102
|
+
# commonly ignored for libraries.
|
|
103
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
104
|
+
#poetry.lock
|
|
105
|
+
|
|
106
|
+
# pdm
|
|
107
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
108
|
+
#pdm.lock
|
|
109
|
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
|
110
|
+
# in version control.
|
|
111
|
+
# https://pdm.fming.dev/#use-with-ide
|
|
112
|
+
.pdm.toml
|
|
113
|
+
|
|
114
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
95
115
|
__pypackages__/
|
|
96
116
|
|
|
97
117
|
# Celery stuff
|
|
@@ -127,3 +147,23 @@ dmypy.json
|
|
|
127
147
|
|
|
128
148
|
# Pyre type checker
|
|
129
149
|
.pyre/
|
|
150
|
+
|
|
151
|
+
# pytype static type analyzer
|
|
152
|
+
.pytype/
|
|
153
|
+
|
|
154
|
+
# Cython debug symbols
|
|
155
|
+
cython_debug/
|
|
156
|
+
|
|
157
|
+
# PyCharm
|
|
158
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
159
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
160
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
161
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
162
|
+
.idea/
|
|
163
|
+
|
|
164
|
+
## Project
|
|
165
|
+
# Version file
|
|
166
|
+
_version.py
|
|
167
|
+
|
|
168
|
+
#OS Files
|
|
169
|
+
*DS_Store
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
default_language_version:
|
|
2
|
+
python: python3.12
|
|
3
|
+
|
|
4
|
+
repos:
|
|
5
|
+
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
6
|
+
rev: v6.0.0
|
|
7
|
+
hooks:
|
|
8
|
+
- id: trailing-whitespace
|
|
9
|
+
- id: end-of-file-fixer
|
|
10
|
+
- id: check-ast
|
|
11
|
+
|
|
12
|
+
- repo: https://github.com/astral-sh/ruff-pre-commit
|
|
13
|
+
rev: v0.16.8
|
|
14
|
+
hooks:
|
|
15
|
+
# Run the linter.
|
|
16
|
+
- id: ruff-check
|
|
17
|
+
args: [--fix]
|
|
18
|
+
# Run the formatter.
|
|
19
|
+
- id: ruff-format
|
|
20
|
+
|
|
21
|
+
- repo: https://github.com/astral-sh/uv-pre-commit
|
|
22
|
+
rev: 0.12.18
|
|
23
|
+
hooks:
|
|
24
|
+
# Ensure the lockfile is up-to-date with pyproject.toml
|
|
25
|
+
- id: uv-lock
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.12
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# pytest-loguru
|
|
2
|
+
|
|
3
|
+
A pytest plugin to add support for [loguru](https://github.com/Delgan/loguru) to pytest's `caplog` fixture. It hooks loguru into pytest's standard `LogCaptureFixture` so that `caplog` captures loguru log records just like standard Python `logging` records.
|
|
4
|
+
|
|
5
|
+
## Development
|
|
6
|
+
|
|
7
|
+
### Environment
|
|
8
|
+
|
|
9
|
+
Development is currently done using Python 3.12. The environment can be created with:
|
|
10
|
+
|
|
11
|
+
```shell
|
|
12
|
+
uv sync
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
This creates a `.venv` folder with the versions specified in the project's `uv.lock` file.
|
|
16
|
+
|
|
17
|
+
### Pre-commit
|
|
18
|
+
|
|
19
|
+
pre-commit will be installed when syncing uv. It is run every time you make a git commit if you call it like this:
|
|
20
|
+
|
|
21
|
+
```shell
|
|
22
|
+
pre-commit install
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
With pre-commit, all code is formatted according to [ruff](https://docs.astral.sh/ruff/) guidelines, and the `uv.lock` file is kept up-to-date.
|
|
26
|
+
|
|
27
|
+
To check if your changes pass pre-commit without committing, run:
|
|
28
|
+
|
|
29
|
+
```shell
|
|
30
|
+
pre-commit run --all-files
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Packages
|
|
34
|
+
|
|
35
|
+
[uv](https://github.com/astral-sh/uv) is used for package management. If you've introduced a new package to the source code (i.e. anywhere in `src/`), please add it to the `project.dependencies` section of `pyproject.toml` with any known version constraints.
|
|
36
|
+
|
|
37
|
+
To add packages required only for testing or development, add them to the `[dependency-groups]` section in `pyproject.toml`.
|
|
38
|
+
|
|
39
|
+
Any changes to the dependencies will be automatically reflected in `uv.lock` with `pre-commit`, but you can re-generate the file without committing by executing:
|
|
40
|
+
|
|
41
|
+
```shell
|
|
42
|
+
uv lock --upgrade
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Project
|
|
46
|
+
|
|
47
|
+
[uv](https://github.com/astral-sh/uv) is used for project management. The project can be built using:
|
|
48
|
+
|
|
49
|
+
```shell
|
|
50
|
+
uv build
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Linting and syntax checking can be run with:
|
|
54
|
+
|
|
55
|
+
```shell
|
|
56
|
+
uv run ruff format --check
|
|
57
|
+
uv run ruff check
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Tests can be executed using:
|
|
61
|
+
|
|
62
|
+
```shell
|
|
63
|
+
uv run pytest
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Coverage must stay at 100%. Measure it with `coverage run` rather than
|
|
67
|
+
pytest-cov, which starts too late to see the plugin's import:
|
|
68
|
+
|
|
69
|
+
```shell
|
|
70
|
+
uv run coverage run -m pytest
|
|
71
|
+
uv run coverage report
|
|
72
|
+
```
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
The development workflow (setting up the environment with `uv sync`,
|
|
4
|
+
installing and running pre-commit, running the tests with `uv run pytest`,
|
|
5
|
+
managing dependencies and building with `uv build`) is documented in the
|
|
6
|
+
[Development](README.md#development) section of the README.
|
|
7
|
+
|
|
8
|
+
Please make sure `pre-commit run --all-files` and `uv run pytest` pass
|
|
9
|
+
before opening a pull request; CI runs both.
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: pytest-loguru
|
|
3
|
+
Version: 0.4.2
|
|
4
|
+
Summary: Pytest Loguru
|
|
5
|
+
Project-URL: Homepage, https://github.com/mcarans/pytest-loguru
|
|
6
|
+
Author: Michael Rans
|
|
7
|
+
License: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Keywords: loguru,py.test,pytest
|
|
10
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
11
|
+
Classifier: Framework :: Pytest
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Natural Language :: English
|
|
15
|
+
Classifier: Operating System :: MacOS
|
|
16
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
17
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
18
|
+
Classifier: Operating System :: Unix
|
|
19
|
+
Classifier: Programming Language :: Python
|
|
20
|
+
Classifier: Programming Language :: Python :: 3
|
|
21
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
25
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
26
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
27
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
28
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
29
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
30
|
+
Classifier: Typing :: Typed
|
|
31
|
+
Requires-Python: >=3.8
|
|
32
|
+
Requires-Dist: loguru
|
|
33
|
+
Requires-Dist: pytest>=6.2
|
|
34
|
+
Description-Content-Type: text/markdown
|
|
35
|
+
|
|
36
|
+
[](https://github.com/mcarans/pytest-loguru/actions/workflows/run-python-tests.yaml)
|
|
37
|
+
[](https://pypi.python.org/pypi/pytest-loguru)
|
|
38
|
+
[](https://anaconda.org/conda-forge/pytest-loguru)
|
|
39
|
+
[](https://coveralls.io/github/mcarans/pytest-loguru?branch=main)
|
|
40
|
+
[](https://github.com/astral-sh/ruff)
|
|
41
|
+
[](https://pypistats.org/packages/pytest-loguru)
|
|
42
|
+
|
|
43
|
+
### pytest-loguru
|
|
44
|
+
|
|
45
|
+
A pytest plugin to add support for loguru to pytest's caplog fixture.
|
|
46
|
+
|
|
47
|
+
You can install it from pypi with:
|
|
48
|
+
|
|
49
|
+
```shell
|
|
50
|
+
pip install pytest-loguru
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
and from conda-forge with:
|
|
54
|
+
|
|
55
|
+
```shell
|
|
56
|
+
conda install -c conda-forge pytest-loguru
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Usage
|
|
60
|
+
|
|
61
|
+
Once installed, the plugin is registered automatically through pytest's
|
|
62
|
+
`pytest11` entry point, so no import or configuration is needed. Messages
|
|
63
|
+
logged with loguru show up in `caplog` just like standard `logging` records,
|
|
64
|
+
and `caplog.at_level` / `caplog.set_level` filter them as usual:
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
import logging
|
|
68
|
+
|
|
69
|
+
from loguru import logger
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def test_logs(caplog):
|
|
73
|
+
logger.warning("something happened")
|
|
74
|
+
assert "something happened" in caplog.text
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def test_levels(caplog):
|
|
78
|
+
with caplog.at_level(logging.ERROR):
|
|
79
|
+
logger.info("ignored")
|
|
80
|
+
logger.error("kept")
|
|
81
|
+
assert caplog.messages == ["kept"]
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Loguru records also reach pytest's other log handlers, in every test
|
|
85
|
+
whether or not it requests `caplog`: they appear under "Captured log call"
|
|
86
|
+
when a test fails, and in the live log when `log_cli` is enabled. Each
|
|
87
|
+
handler's level (`log_level`, `log_cli_level`) filters them as it does
|
|
88
|
+
standard `logging` records. Loguru's own sinks, such as the default stderr
|
|
89
|
+
one, are left alone.
|
|
90
|
+
|
|
91
|
+
Note that coverage is 100% but the coverage tool is confused by the fixture decorator.
|
|
92
|
+
|
|
93
|
+
# Development
|
|
94
|
+
|
|
95
|
+
## Environment
|
|
96
|
+
|
|
97
|
+
Development is currently done using Python 3.12. The environment can be created with:
|
|
98
|
+
|
|
99
|
+
```shell
|
|
100
|
+
uv sync
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
This creates a `.venv` folder with the versions specified in the project's `uv.lock` file.
|
|
104
|
+
|
|
105
|
+
### Pre-commit
|
|
106
|
+
|
|
107
|
+
pre-commit will be installed when syncing uv. It is run every time you make a git commit if you call it like this:
|
|
108
|
+
|
|
109
|
+
```shell
|
|
110
|
+
pre-commit install
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
With pre-commit, all code is formatted according to [ruff](https://docs.astral.sh/ruff/) guidelines.
|
|
114
|
+
|
|
115
|
+
To check if your changes pass pre-commit without committing, run:
|
|
116
|
+
|
|
117
|
+
```shell
|
|
118
|
+
pre-commit run --all-files
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Packages
|
|
122
|
+
|
|
123
|
+
[uv](https://github.com/astral-sh/uv) is used for package management. If you've introduced a new package to the source code (i.e. anywhere in `src/`), please add it to the `project.dependencies` section of `pyproject.toml` with any known version constraints.
|
|
124
|
+
|
|
125
|
+
To add packages required only for testing or development, add them to the `[dependency-groups]` section in `pyproject.toml`.
|
|
126
|
+
|
|
127
|
+
Any changes to the dependencies will be automatically reflected in `uv.lock` with `pre-commit`, but you can re-generate the file without committing by executing:
|
|
128
|
+
|
|
129
|
+
```shell
|
|
130
|
+
uv lock --upgrade
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Project
|
|
134
|
+
|
|
135
|
+
[uv](https://github.com/astral-sh/uv) is used for project management. The project can be built using:
|
|
136
|
+
|
|
137
|
+
```shell
|
|
138
|
+
uv build
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
Linting and syntax checking can be run with:
|
|
142
|
+
|
|
143
|
+
```shell
|
|
144
|
+
uv run ruff format --check
|
|
145
|
+
uv run ruff check
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Tests can be executed using:
|
|
149
|
+
|
|
150
|
+
```shell
|
|
151
|
+
uv run pytest
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
Coverage must stay at 100%. Measure it with `coverage run` rather than
|
|
155
|
+
pytest-cov, which starts too late to see the plugin's import:
|
|
156
|
+
|
|
157
|
+
```shell
|
|
158
|
+
uv run coverage run -m pytest
|
|
159
|
+
uv run coverage report
|
|
160
|
+
```
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
[](https://github.com/mcarans/pytest-loguru/actions/workflows/run-python-tests.yaml)
|
|
2
|
+
[](https://pypi.python.org/pypi/pytest-loguru)
|
|
3
|
+
[](https://anaconda.org/conda-forge/pytest-loguru)
|
|
4
|
+
[](https://coveralls.io/github/mcarans/pytest-loguru?branch=main)
|
|
5
|
+
[](https://github.com/astral-sh/ruff)
|
|
6
|
+
[](https://pypistats.org/packages/pytest-loguru)
|
|
7
|
+
|
|
8
|
+
### pytest-loguru
|
|
9
|
+
|
|
10
|
+
A pytest plugin to add support for loguru to pytest's caplog fixture.
|
|
11
|
+
|
|
12
|
+
You can install it from pypi with:
|
|
13
|
+
|
|
14
|
+
```shell
|
|
15
|
+
pip install pytest-loguru
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
and from conda-forge with:
|
|
19
|
+
|
|
20
|
+
```shell
|
|
21
|
+
conda install -c conda-forge pytest-loguru
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
Once installed, the plugin is registered automatically through pytest's
|
|
27
|
+
`pytest11` entry point, so no import or configuration is needed. Messages
|
|
28
|
+
logged with loguru show up in `caplog` just like standard `logging` records,
|
|
29
|
+
and `caplog.at_level` / `caplog.set_level` filter them as usual:
|
|
30
|
+
|
|
31
|
+
```python
|
|
32
|
+
import logging
|
|
33
|
+
|
|
34
|
+
from loguru import logger
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def test_logs(caplog):
|
|
38
|
+
logger.warning("something happened")
|
|
39
|
+
assert "something happened" in caplog.text
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def test_levels(caplog):
|
|
43
|
+
with caplog.at_level(logging.ERROR):
|
|
44
|
+
logger.info("ignored")
|
|
45
|
+
logger.error("kept")
|
|
46
|
+
assert caplog.messages == ["kept"]
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Loguru records also reach pytest's other log handlers, in every test
|
|
50
|
+
whether or not it requests `caplog`: they appear under "Captured log call"
|
|
51
|
+
when a test fails, and in the live log when `log_cli` is enabled. Each
|
|
52
|
+
handler's level (`log_level`, `log_cli_level`) filters them as it does
|
|
53
|
+
standard `logging` records. Loguru's own sinks, such as the default stderr
|
|
54
|
+
one, are left alone.
|
|
55
|
+
|
|
56
|
+
Note that coverage is 100% but the coverage tool is confused by the fixture decorator.
|
|
57
|
+
|
|
58
|
+
# Development
|
|
59
|
+
|
|
60
|
+
## Environment
|
|
61
|
+
|
|
62
|
+
Development is currently done using Python 3.12. The environment can be created with:
|
|
63
|
+
|
|
64
|
+
```shell
|
|
65
|
+
uv sync
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
This creates a `.venv` folder with the versions specified in the project's `uv.lock` file.
|
|
69
|
+
|
|
70
|
+
### Pre-commit
|
|
71
|
+
|
|
72
|
+
pre-commit will be installed when syncing uv. It is run every time you make a git commit if you call it like this:
|
|
73
|
+
|
|
74
|
+
```shell
|
|
75
|
+
pre-commit install
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
With pre-commit, all code is formatted according to [ruff](https://docs.astral.sh/ruff/) guidelines.
|
|
79
|
+
|
|
80
|
+
To check if your changes pass pre-commit without committing, run:
|
|
81
|
+
|
|
82
|
+
```shell
|
|
83
|
+
pre-commit run --all-files
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Packages
|
|
87
|
+
|
|
88
|
+
[uv](https://github.com/astral-sh/uv) is used for package management. If you've introduced a new package to the source code (i.e. anywhere in `src/`), please add it to the `project.dependencies` section of `pyproject.toml` with any known version constraints.
|
|
89
|
+
|
|
90
|
+
To add packages required only for testing or development, add them to the `[dependency-groups]` section in `pyproject.toml`.
|
|
91
|
+
|
|
92
|
+
Any changes to the dependencies will be automatically reflected in `uv.lock` with `pre-commit`, but you can re-generate the file without committing by executing:
|
|
93
|
+
|
|
94
|
+
```shell
|
|
95
|
+
uv lock --upgrade
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Project
|
|
99
|
+
|
|
100
|
+
[uv](https://github.com/astral-sh/uv) is used for project management. The project can be built using:
|
|
101
|
+
|
|
102
|
+
```shell
|
|
103
|
+
uv build
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Linting and syntax checking can be run with:
|
|
107
|
+
|
|
108
|
+
```shell
|
|
109
|
+
uv run ruff format --check
|
|
110
|
+
uv run ruff check
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Tests can be executed using:
|
|
114
|
+
|
|
115
|
+
```shell
|
|
116
|
+
uv run pytest
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Coverage must stay at 100%. Measure it with `coverage run` rather than
|
|
120
|
+
pytest-cov, which starts too late to see the plugin's import:
|
|
121
|
+
|
|
122
|
+
```shell
|
|
123
|
+
uv run coverage run -m pytest
|
|
124
|
+
uv run coverage report
|
|
125
|
+
```
|