Pytest Allure Step Logger
A robust, plug-and-play logging integration for pytest and Allure. Automatically captures, buffers, and attaches logs to Allure test steps—no code changes required. Highly configurable, thread-safe, and designed for clean, isolated test reporting.
Table of Contents
- Features
- Installation
- Quick Start
- Usage
- API Reference
- Behavioral Details
- Requirements
- Development
- Contributing
- License
- Changelog
Features
- Automatic Log Capture: All logging calls are captured and buffered, even outside decorators.
- Allure Step Integration: Logs are attached to Allure test steps for traceability.
- Thread-Safe: Each test/thread gets its own buffer.
- Automatic Cleanup: Log buffer is cleared before each test to prevent log mixing.
- Highly Configurable: Buffer size, log format, min log level, auto-flush, and more.
- Zero Code Changes: Works with standard
loggingcalls out of the box. - Manual & Decorator Support: Use decorators for step-level logs, or log directly.
Installation
pip install pytest-allure-step
Note: Allure reports require the Allure CLI to be installed and available in your PATH.
Quick Start
Basic Usage with Decorator
import logging
from pytest_allure_step import allure_step
@allure_step("My Test Step")
def my_step():
logging.info("This log will be captured and attached to the Allure step")
logging.error("Error messages are also captured")
return True
def test_example():
result = my_step()
assert result
Direct Logging (No Decorator)
from pytest_allure_step import info, warning, error, debug, critical, log
def test_direct_logging():
info("This is an info message")
warning("This is a warning")
error("This is an error")
debug("Debug message")
critical("Critical error!")
log(25, "Custom log level message")
assert True
Usage
Logging Inside and Outside Decorators
- Inside
@allure_step: Logs are attached to the step and flushed at the end. - Outside decorator: Logs are buffered and auto-flushed on buffer overflow. Remaining logs are not attached unless you flush or use a decorator.
Example: Buffer Overflow (Auto-Flush)
from pytest_allure_step import configure, info
def test_buffer():
configure(buffer_size=3)
for i in range(5):
info(f"Message {i}") # After 3, auto-flush triggers and attaches logs
Manual Log Clearing
from pytest_allure_step import clear_logs, info
def test_manual_clear():
info("Before clear")
clear_logs() # Flushes and clears buffer
info("After clear")
Configuration
from pytest_allure_step import configure, set_log_level
configure(
buffer_size=500,
min_log_level="WARNING",
log_format="[{timestamp}] {level} | {message}",
auto_flush=True
)
set_log_level("ERROR")
Configuration Options
| Option | Default | Description |
|---|---|---|
buffer_size |
1000 | Max logs before auto-flush |
include_timestamp |
True | Include timestamps in log messages |
log_format |
"[{timestamp}] {level}: {message}" |
Custom log format string |
auto_flush |
True | Auto-flush on buffer overflow |
min_log_level |
"DEBUG" | Minimum log level to capture |
Best Practices
- Use
@allure_stepfor step-level log grouping. - For logs outside decorators, call
clear_logs()at the end if you want all logs attached. - Adjust
buffer_sizefor your test suite’s needs. - Use
set_log_levelto reduce noise in large test runs.
Troubleshooting
- Logs missing in Allure?
- Ensure you use the decorator or call
clear_logs()at the end of your test. - Check your buffer size and auto-flush settings.
- Ensure you use the decorator or call
- Allure CLI not found?
- Install Allure CLI and add it to your PATH.
- Log mixing between tests?
- Automatic cleanup is enabled by default; if you see mixing, check for custom threading or multiprocessing.
API Reference
Logging Functions
critical(message, *args, **kwargs)error(message, *args, **kwargs)warning(message, *args, **kwargs)info(message, *args, **kwargs)debug(message, *args, **kwargs)log(level, message, *args, **kwargs)
Configuration Functions
configure(**kwargs)get_config()reset_config()set_buffer_size(size)set_log_level(level)enable_auto_flush()disable_auto_flush()clear_logs()
Decorators
@allure_step(step_name)
Fixtures
- Automatic log cleaning: A pytest fixture is included and enabled by default, clearing the log buffer before each test.
Behavioral Details
- Buffering: Logs are buffered in thread-local storage.
- Auto-Flush: When buffer exceeds
buffer_size, logs are attached to Allure and buffer is cleared. - Decorator:
@allure_stepflushes logs at the end of the step. - Manual Clear:
clear_logs()flushes and clears the buffer. - Automatic Cleanup: Buffer is cleared before each test (via fixture).
- Thread Safety: Each thread/test gets its own buffer.
Requirements
- Python 3.7+
- pytest >= 6.0.0
- allure-pytest >= 2.9.0
Development
Install for Development
git clone https://github.com/deekshith-poojary98/pytest-allure-step.git
cd pytest-allure-step
pip install -e .[dev]
Run Tests
pytest
Code Quality
black pytest_allure_step/
flake8 pytest_allure_step/
mypy pytest_allure_step/
Contributing
- Fork the repository
- Create a feature branch
- Make your changes (add tests!)
- Run the test suite
- Submit a pull request
Please see CONTRIBUTING.md and CODE_OF_CONDUCT.md for details.
License
MIT License. See LICENSE.
Changelog
See CHANGELOG.md for release history.
Metadata
Release files for pytest-allure-step 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pytest_allure_step-0.1.0.tar.gz | 9.3 kB | Without provenance | Details for pytest_allure_step-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pytest_allure_step-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for pytest_allure_step-0.1.0-py3-none-any.whl |
Total release size: 16.8 kB
Release files / pytest_allure_step-0.1.0.tar.gz
| Download URL | pytest_allure_step-0.1.0.tar.gz |
|---|---|
| Size | 9.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b2a9472172a6c8b077fba757e047ccb08040253bd069d34a464ed71965bbc6c0
|
|
BLAKE2b-256 checksum How to use checksums |
0fe8c6afc5f58188000993e7c2772019e4736fccb64348564ad62202e277da93
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.5
|
Release files / pytest_allure_step-0.1.0-py3-none-any.whl
| Download URL | pytest_allure_step-0.1.0-py3-none-any.whl |
|---|---|
| Size | 7.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bcad7cbbce36c401ca5dcb35b0f12ce9863479085450514adb5d32c48cf948c7
|
|
BLAKE2b-256 checksum How to use checksums |
96ac36597953fbcdb6f445b2278b85c4a778dae4c4228a7857481ba86399f318
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.5
|
Security for pytest-allure-step 0.1.0
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.