Skip to main content

Rewrite Allure step titles without nesting

Project description

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! ⭐

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

allure_step_rewriter-0.2.1.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

allure_step_rewriter-0.2.1-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file allure_step_rewriter-0.2.1.tar.gz.

File metadata

  • Download URL: allure_step_rewriter-0.2.1.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.4

File hashes

Hashes for allure_step_rewriter-0.2.1.tar.gz
Algorithm Hash digest
SHA256 1b0fe09e55b6a217ce7087c89e622897e9451c8ee4cf75e93ab303809918942a
MD5 42419894c2ef49fa3ecee9df10956024
BLAKE2b-256 3ecdc0d6e64cc625d99431a8fca2fb517d33554dac031c5d9b631513941747e2

See more details on using hashes here.

File details

Details for the file allure_step_rewriter-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for allure_step_rewriter-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 232cedb96778abee70b4db55a432abdad8f40b3d3159e800a45a2c6fb9745ae6
MD5 2942844df746de7610e3a698258cfccf
BLAKE2b-256 1fcaf01929536d288790703a3f37ab261a5926ebe66071449484302f898ba7d2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page