Mirakuru

3.0.2 · active · verified Thu Apr 09

Mirakuru is a Python library designed for process orchestration, primarily used in functional and integration tests. It facilitates starting and stopping external processes (such as databases, APIs, or other services) and waiting for a clear indication that they are ready before allowing the main application or test suite to proceed. The library is currently at version 3.0.2 and is actively maintained, with releases typically addressing bug fixes, enhancements, and compatibility updates.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `TCPExecutor` to ensure a local HTTP server (simulated here with Python's built-in `http.server`) is ready to accept connections on a specific port before proceeding. It also shows proper cleanup. Mirakuru's executors can also be used as context managers for automatic startup and shutdown.

import subprocess
import time
from mirakuru import TCPExecutor

# This simulates a simple HTTP server. In a real scenario, this would be your external service.
server_process = None
try:
    # Start a simple Python HTTP server in the background
    server_process = subprocess.Popen(['python', '-m', 'http.server', '8000'], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
    
    # Use TCPExecutor to wait for the server to be ready on port 8000
    http_executor = TCPExecutor('echo server_started', host='localhost', port=8000)
    
    print("Waiting for HTTP server to start...")
    http_executor.start()
    print("HTTP server is ready on port 8000.")
    
    # Your application or test code that interacts with the server would go here.
    # For demonstration, we'll just wait a bit.
    time.sleep(2)
    
    print("Stopping HTTP server.")
    http_executor.stop()
    print("HTTP server stopped.")
finally:
    if server_process:
        server_process.terminate()
        server_process.wait()

view raw JSON →