pytest-allure-step


Namepytest-allure-step JSON
Version 0.1.0 PyPI version JSON
download
home_pageNone
SummaryEnhanced logging integration with Allure reports for pytest
upload_time2025-07-13 09:17:18
maintainerNone
docs_urlNone
authorNone
requires_python>=3.7
licenseMIT
keywords pytest allure logging testing
VCS
bugtrack_url
requirements allure-pytest pytest
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Pytest Allure Step Logger

[![PyPI version](https://badge.fury.io/py/pytest-allure-step.svg)](https://badge.fury.io/py/pytest-allure-step)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
[![Python](https://img.shields.io/pypi/pyversions/pytest-allure-step.svg)](https://pypi.org/project/pytest-allure-step/)

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](#features)
- [Installation](#installation)
- [Quick Start](#quick-start)
- [Usage](#usage)
  - [Logging Inside and Outside Decorators](#logging-inside-and-outside-decorators)
  - [Manual Log Clearing](#manual-log-clearing)
  - [Configuration](#configuration)
  - [Best Practices](#best-practices)
  - [Troubleshooting](#troubleshooting)
- [API Reference](#api-reference)
- [Behavioral Details](#behavioral-details)
- [Requirements](#requirements)
- [Development](#development)
- [Contributing](#contributing)
- [License](#license)
- [Changelog](#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 `logging` calls out of the box.
- **Manual & Decorator Support**: Use decorators for step-level logs, or log directly.

---

## Installation

```bash
pip install pytest-allure-step
```

> **Note:** Allure reports require the [Allure CLI](https://docs.qameta.io/allure/#_installing_a_commandline) to be installed and available in your PATH.

---

## Quick Start

### Basic Usage with Decorator
```python
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)
```python
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)
```python
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
```python
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
```python
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_step` for step-level log grouping.
- For logs outside decorators, call `clear_logs()` at the end if you want all logs attached.
- Adjust `buffer_size` for your test suite’s needs.
- Use `set_log_level` to 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.
- **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_step` flushes 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
```bash
git clone https://github.com/deekshith-poojary98/pytest-allure-step.git
cd pytest-allure-step
pip install -e .[dev]
```

### Run Tests
```bash
pytest
```

### Code Quality
```bash
black pytest_allure_step/
flake8 pytest_allure_step/
mypy pytest_allure_step/
```

---

## Contributing
1. Fork the repository
2. Create a feature branch
3. Make your changes (add tests!)
4. Run the test suite
5. Submit a pull request

Please see [CONTRIBUTING.md](CONTRIBUTING.md) and [CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md) for details.

---

## License
MIT License. See [LICENSE](LICENSE).

---

## Changelog

See [CHANGELOG.md](CHANGELOG.md) for release history. 

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "pytest-allure-step",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "Deekshith Poojary <deekshithpoojary355@gmail.com>",
    "keywords": "pytest, allure, logging, testing",
    "author": null,
    "author_email": "Deekshith Poojary <deekshithpoojary355@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/0f/e8/c6afc5f58188000993e7c2772019e4736fccb64348564ad62202e277da93/pytest_allure_step-0.1.0.tar.gz",
    "platform": null,
    "description": "# Pytest Allure Step Logger\r\n\r\n[![PyPI version](https://badge.fury.io/py/pytest-allure-step.svg)](https://badge.fury.io/py/pytest-allure-step)\r\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)\r\n[![Python](https://img.shields.io/pypi/pyversions/pytest-allure-step.svg)](https://pypi.org/project/pytest-allure-step/)\r\n\r\nA robust, plug-and-play logging integration for pytest and Allure. Automatically captures, buffers, and attaches logs to Allure test steps\u2014no code changes required. Highly configurable, thread-safe, and designed for clean, isolated test reporting.\r\n\r\n---\r\n\r\n## Table of Contents\r\n- [Features](#features)\r\n- [Installation](#installation)\r\n- [Quick Start](#quick-start)\r\n- [Usage](#usage)\r\n  - [Logging Inside and Outside Decorators](#logging-inside-and-outside-decorators)\r\n  - [Manual Log Clearing](#manual-log-clearing)\r\n  - [Configuration](#configuration)\r\n  - [Best Practices](#best-practices)\r\n  - [Troubleshooting](#troubleshooting)\r\n- [API Reference](#api-reference)\r\n- [Behavioral Details](#behavioral-details)\r\n- [Requirements](#requirements)\r\n- [Development](#development)\r\n- [Contributing](#contributing)\r\n- [License](#license)\r\n- [Changelog](#changelog)\r\n\r\n---\r\n\r\n## Features\r\n- **Automatic Log Capture**: All logging calls are captured and buffered, even outside decorators.\r\n- **Allure Step Integration**: Logs are attached to Allure test steps for traceability.\r\n- **Thread-Safe**: Each test/thread gets its own buffer.\r\n- **Automatic Cleanup**: Log buffer is cleared before each test to prevent log mixing.\r\n- **Highly Configurable**: Buffer size, log format, min log level, auto-flush, and more.\r\n- **Zero Code Changes**: Works with standard `logging` calls out of the box.\r\n- **Manual & Decorator Support**: Use decorators for step-level logs, or log directly.\r\n\r\n---\r\n\r\n## Installation\r\n\r\n```bash\r\npip install pytest-allure-step\r\n```\r\n\r\n> **Note:** Allure reports require the [Allure CLI](https://docs.qameta.io/allure/#_installing_a_commandline) to be installed and available in your PATH.\r\n\r\n---\r\n\r\n## Quick Start\r\n\r\n### Basic Usage with Decorator\r\n```python\r\nimport logging\r\nfrom pytest_allure_step import allure_step\r\n\r\n@allure_step(\"My Test Step\")\r\ndef my_step():\r\n    logging.info(\"This log will be captured and attached to the Allure step\")\r\n    logging.error(\"Error messages are also captured\")\r\n    return True\r\n\r\ndef test_example():\r\n    result = my_step()\r\n    assert result\r\n```\r\n\r\n### Direct Logging (No Decorator)\r\n```python\r\nfrom pytest_allure_step import info, warning, error, debug, critical, log\r\n\r\ndef test_direct_logging():\r\n    info(\"This is an info message\")\r\n    warning(\"This is a warning\")\r\n    error(\"This is an error\")\r\n    debug(\"Debug message\")\r\n    critical(\"Critical error!\")\r\n    log(25, \"Custom log level message\")\r\n    assert True\r\n```\r\n\r\n---\r\n\r\n## Usage\r\n\r\n### Logging Inside and Outside Decorators\r\n- **Inside `@allure_step`**: Logs are attached to the step and flushed at the end.\r\n- **Outside decorator**: Logs are buffered and auto-flushed on buffer overflow. Remaining logs are not attached unless you flush or use a decorator.\r\n\r\n#### Example: Buffer Overflow (Auto-Flush)\r\n```python\r\nfrom pytest_allure_step import configure, info\r\n\r\ndef test_buffer():\r\n    configure(buffer_size=3)\r\n    for i in range(5):\r\n        info(f\"Message {i}\")  # After 3, auto-flush triggers and attaches logs\r\n```\r\n\r\n### Manual Log Clearing\r\n```python\r\nfrom pytest_allure_step import clear_logs, info\r\n\r\ndef test_manual_clear():\r\n    info(\"Before clear\")\r\n    clear_logs()  # Flushes and clears buffer\r\n    info(\"After clear\")\r\n```\r\n\r\n### Configuration\r\n```python\r\nfrom pytest_allure_step import configure, set_log_level\r\n\r\nconfigure(\r\n    buffer_size=500,\r\n    min_log_level=\"WARNING\",\r\n    log_format=\"[{timestamp}] {level} | {message}\",\r\n    auto_flush=True\r\n)\r\nset_log_level(\"ERROR\")\r\n```\r\n\r\n#### Configuration Options\r\n| Option              | Default                                 | Description                           |\r\n|---------------------|-----------------------------------------|---------------------------------------|\r\n| `buffer_size`       | 1000                                    | Max logs before auto-flush            |\r\n| `include_timestamp` | True                                    | Include timestamps in log messages    |\r\n| `log_format`        | `\"[{timestamp}] {level}: {message}\"`    | Custom log format string              |\r\n| `auto_flush`        | True                                    | Auto-flush on buffer overflow         |\r\n| `min_log_level`     | \"DEBUG\"                                 | Minimum log level to capture          |\r\n\r\n### Best Practices\r\n- Use `@allure_step` for step-level log grouping.\r\n- For logs outside decorators, call `clear_logs()` at the end if you want all logs attached.\r\n- Adjust `buffer_size` for your test suite\u2019s needs.\r\n- Use `set_log_level` to reduce noise in large test runs.\r\n\r\n### Troubleshooting\r\n- **Logs missing in Allure?**\r\n  - Ensure you use the decorator or call `clear_logs()` at the end of your test.\r\n  - Check your buffer size and auto-flush settings.\r\n- **Allure CLI not found?**\r\n  - Install Allure CLI and add it to your PATH.\r\n- **Log mixing between tests?**\r\n  - Automatic cleanup is enabled by default; if you see mixing, check for custom threading or multiprocessing.\r\n\r\n---\r\n\r\n## API Reference\r\n\r\n### Logging Functions\r\n- `critical(message, *args, **kwargs)`\r\n- `error(message, *args, **kwargs)`\r\n- `warning(message, *args, **kwargs)`\r\n- `info(message, *args, **kwargs)`\r\n- `debug(message, *args, **kwargs)`\r\n- `log(level, message, *args, **kwargs)`\r\n\r\n### Configuration Functions\r\n- `configure(**kwargs)`\r\n- `get_config()`\r\n- `reset_config()`\r\n- `set_buffer_size(size)`\r\n- `set_log_level(level)`\r\n- `enable_auto_flush()`\r\n- `disable_auto_flush()`\r\n- `clear_logs()`\r\n\r\n### Decorators\r\n- `@allure_step(step_name)`\r\n\r\n### Fixtures\r\n- **Automatic log cleaning**: A pytest fixture is included and enabled by default, clearing the log buffer before each test.\r\n\r\n---\r\n\r\n## Behavioral Details\r\n- **Buffering**: Logs are buffered in thread-local storage.\r\n- **Auto-Flush**: When buffer exceeds `buffer_size`, logs are attached to Allure and buffer is cleared.\r\n- **Decorator**: `@allure_step` flushes logs at the end of the step.\r\n- **Manual Clear**: `clear_logs()` flushes and clears the buffer.\r\n- **Automatic Cleanup**: Buffer is cleared before each test (via fixture).\r\n- **Thread Safety**: Each thread/test gets its own buffer.\r\n\r\n---\r\n\r\n## Requirements\r\n- Python 3.7+\r\n- pytest >= 6.0.0\r\n- allure-pytest >= 2.9.0\r\n\r\n---\r\n\r\n## Development\r\n\r\n### Install for Development\r\n```bash\r\ngit clone https://github.com/deekshith-poojary98/pytest-allure-step.git\r\ncd pytest-allure-step\r\npip install -e .[dev]\r\n```\r\n\r\n### Run Tests\r\n```bash\r\npytest\r\n```\r\n\r\n### Code Quality\r\n```bash\r\nblack pytest_allure_step/\r\nflake8 pytest_allure_step/\r\nmypy pytest_allure_step/\r\n```\r\n\r\n---\r\n\r\n## Contributing\r\n1. Fork the repository\r\n2. Create a feature branch\r\n3. Make your changes (add tests!)\r\n4. Run the test suite\r\n5. Submit a pull request\r\n\r\nPlease see [CONTRIBUTING.md](CONTRIBUTING.md) and [CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md) for details.\r\n\r\n---\r\n\r\n## License\r\nMIT License. See [LICENSE](LICENSE).\r\n\r\n---\r\n\r\n## Changelog\r\n\r\nSee [CHANGELOG.md](CHANGELOG.md) for release history. \r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Enhanced logging integration with Allure reports for pytest",
    "version": "0.1.0",
    "project_urls": {
        "Bug Tracker": "https://github.com/deekshith-poojary98/pytest-allure-step/issues",
        "Changelog": "https://github.com/deekshith-poojary98/pytest-allure-step/blob/main/CHANGELOG.md",
        "Documentation": "https://github.com/deekshith-poojary98/pytest-allure-step#readme",
        "Homepage": "https://github.com/deekshith-poojary98/pytest-allure-step",
        "Repository": "https://github.com/deekshith-poojary98/pytest-allure-step",
        "Source": "https://github.com/deekshith-poojary98/pytest-allure-step"
    },
    "split_keywords": [
        "pytest",
        " allure",
        " logging",
        " testing"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "96ac36597953fbcdb6f445b2278b85c4a778dae4c4228a7857481ba86399f318",
                "md5": "3ce48ecf19554873bc5ba271ab3368e7",
                "sha256": "bcad7cbbce36c401ca5dcb35b0f12ce9863479085450514adb5d32c48cf948c7"
            },
            "downloads": -1,
            "filename": "pytest_allure_step-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3ce48ecf19554873bc5ba271ab3368e7",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 7504,
            "upload_time": "2025-07-13T09:17:16",
            "upload_time_iso_8601": "2025-07-13T09:17:16.899382Z",
            "url": "https://files.pythonhosted.org/packages/96/ac/36597953fbcdb6f445b2278b85c4a778dae4c4228a7857481ba86399f318/pytest_allure_step-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "0fe8c6afc5f58188000993e7c2772019e4736fccb64348564ad62202e277da93",
                "md5": "3db35fbcf851759bb199205a48445c07",
                "sha256": "b2a9472172a6c8b077fba757e047ccb08040253bd069d34a464ed71965bbc6c0"
            },
            "downloads": -1,
            "filename": "pytest_allure_step-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "3db35fbcf851759bb199205a48445c07",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 9268,
            "upload_time": "2025-07-13T09:17:18",
            "upload_time_iso_8601": "2025-07-13T09:17:18.415722Z",
            "url": "https://files.pythonhosted.org/packages/0f/e8/c6afc5f58188000993e7c2772019e4736fccb64348564ad62202e277da93/pytest_allure_step-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-13 09:17:18",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "deekshith-poojary98",
    "github_project": "pytest-allure-step",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "allure-pytest",
            "specs": [
                [
                    ">=",
                    "2.9.0"
                ]
            ]
        },
        {
            "name": "pytest",
            "specs": [
                [
                    ">=",
                    "6.0.0"
                ]
            ]
        }
    ],
    "lcname": "pytest-allure-step"
}
        
Elapsed time: 1.35869s