Skip to main content

Allure Step Rewriter

Python library for rewriting Allure step titles without nesting

License: MIT Python 3.8+

🎯 Problem

In Allure framework, there's no way to override an existing step title. When you try to change the title, it creates a nested step instead:

@allure.step("Default title")
def get_data():
    return api.get("/data")

# In test
with allure.step("Custom title"):  # ❌ Creates nesting!
    get_data()
Result in Allure:
✓ Custom title
  ✓ Default title  # Unwanted nesting

✅ Solution

allure-step-rewriter allows you to rewrite the step title instead of creating nesting:

from allure_step_rewriter import rewrite_step
@rewrite_step("Default title")
def get_data():
    return api.get("/data")

# In test
with rewrite_step("Custom title"):  # ✅ Rewrites!
    get_data()
Result in Allure:
✓ Custom title  # No nesting!

📋 Requirements

  • Python 3.8+
  • allure-pytest >= 2.9.0

Important: allure-pytest is a peer dependency and must be installed separately. This allows you to manage the allure-pytest version yourself without conflicts.

🚀 Installation

Option 1: Install with allure-pytest automatically

pip install allure-step-rewriter[allure]

Option 2: Install separately (recommended)

# First, install allure-pytest (if not already installed)
pip install allure-pytest>=2.9.0

# Then install allure-step-rewriter
pip install allure-step-rewriter

Option 3: For development

pip install allure-step-rewriter[dev]

Note: If you already have allure-pytest installed, just install allure-step-rewriter without extras.

📖 Quick Start

Basic Usage

from allure_step_rewriter import rewrite_step

# As a decorator
@rewrite_step("Get user data")
def get_user_data(user_id):
    return api.get(f"/users/{user_id}")

# In your test
def test_user():
    # Call with default title
    data = get_user_data(123)

    # Or override the title
    data = get_user_data(123, step_title="Fetch admin user")

Multiple Overrides

You can override multiple steps within a single context:

@rewrite_step("Login")
def login(username):
    pass

@rewrite_step("Get data")
def get_data():
    pass

@rewrite_step("Logout")
def logout():
    pass

# All three functions will be overridden to "User Flow"
with rewrite_step("User Flow"):
    login("admin")
    get_data()
    logout()

# Result in Allure: Only one step "User Flow" (no nesting!)

Combining with Nested Steps

When you need hierarchical structure, combine rewrite_step with standard allure.step:

import allure
from allure_step_rewriter import rewrite_step

@rewrite_step("API call")
def api_call():
    pass

with rewrite_step("Test Scenario"):
    api_call()  # Overridden to "Test Scenario"

    # Create nested step using allure.step
    with allure.step("Validation"):
        assert True

    api_call()  # Overridden to "Test Scenario" again

# Result in Allure:
# ✓ Test Scenario
#   ✓ Validation

⚠️ Important Behavior

How rewrite_step Works

rewrite_step does not create nested steps for decorated functions within its context. Instead, it skips creating new steps and uses the existing context:

with rewrite_step("Parent"):
    func_a()  # No step created
    func_b()  # No step created
    func_c()  # No step created
# Result: Only "Parent" step appears in Allure report

When You Need Nested Steps

Use standard allure.step for creating nested steps:

import allure

with rewrite_step("Parent"):
    func_a()  # Overridden to "Parent"

    # Need a nested step? Use allure.step
    with allure.step("Child Step"):
        func_b()  # Creates nested "Child Step"

    func_c()  # Overridden to "Parent"

# Result in Allure:
# ✓ Parent
#   ✓ Child Step

Key Rules

  1. rewrite_step context = Override all decorated functions (no nesting)
  2. allure.step inside rewrite_step = Create nested steps when needed
  3. Multiple overrides = Supported within single context
  4. Thread-safe = Works correctly in parallel test execution

🔧 API Reference

rewrite_step(title: str)

Can be used as both decorator and context manager.

As decorator:

@rewrite_step("Step title")
def my_function():
    pass

# Call with default title
my_function()

# Override title dynamically
my_function(step_title="Custom title")

As context manager:

with rewrite_step("Context title"):
    my_function()  # Overrides to "Context title"

Decorator without parentheses:

@rewrite_step
def my_function():
    pass
# Uses function name as title

📝 License

This project is licensed under the MIT License - see the LICENSE file for details.

👤 Author

Nikita Tulenkov

GitHub: @NikitaTulenkov

LinkedIn: nikita-tulenkov

Email: tulenckov.nikita@gmail.com

⭐ Support

If this library helped you - give it a star! ⭐

Release files for allure-step-rewriter 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for allure-step-rewriter 0.2.1
File Size Uploaded
allure_step_rewriter-0.2.1.tar.gz 9.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for allure-step-rewriter 0.2.1
File Interpreter ABI Platform
allure_step_rewriter-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 17.5 kB

Release files / allure_step_rewriter-0.2.1.tar.gz

Download URL allure_step_rewriter-0.2.1.tar.gz
Size 9.9 kB
Tags Source
SHA-256 checksum
How to use checksums
1b0fe09e55b6a217ce7087c89e622897e9451c8ee4cf75e93ab303809918942a
BLAKE2b-256 checksum
How to use checksums
3ecdc0d6e64cc625d99431a8fca2fb517d33554dac031c5d9b631513941747e2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.4

Release files / allure_step_rewriter-0.2.1-py3-none-any.whl

Download URL allure_step_rewriter-0.2.1-py3-none-any.whl
Size 7.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
232cedb96778abee70b4db55a432abdad8f40b3d3159e800a45a2c6fb9745ae6
BLAKE2b-256 checksum
How to use checksums
1fcaf01929536d288790703a3f37ab261a5926ebe66071449484302f898ba7d2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.4

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page