Skip to content

Test Reporting, Centralized Logging, Makefile & CI Integration#1

Merged
sethorpe merged 6 commits intomainfrom
feature/test-reporting
May 30, 2025
Merged

Test Reporting, Centralized Logging, Makefile & CI Integration#1
sethorpe merged 6 commits intomainfrom
feature/test-reporting

Conversation

@sethorpe
Copy link
Owner

Overview

This PR introduces the test-reporting feature and associated infrastructure:

  1. Test Reporting

    • Adds scripts/allure_helper.py to clean, generate, and serve Allure HTML reports with parameterized paths and structured logging.
    • Integrates Allure into your local workflow via a Makefile target.
  2. Centralized Logging

    • Creates src/api_testing_framework/logger.py which configures the root logger and exposes a shared logger instance.
    • Eliminates ad-hoc print calls and per-module logging boilerplate
  3. Makefile

    • Adds a Makefile with these targets:
      • install -> poetry install --no-root
      • test -> run pytest
      • report -> run purest --alluredir=allure-results + allure generate ...
      • serve-report -> launch interactive report server via scripts/allure_helper.py --serve
      • clean -> remove caches and old reports
      • all -> "clean -> install -> test -> report" full pipeline
  4. CI Integration

    • Adds .github/workflows/ci.yml to run the full test-and-report pipeline on every push, pull_request, or manual dispatch.

    • Steps include:

      1. Checkout code
      2. Cache Poetry's download cache
      3. Setup Java via actions/setup-java@v3
      4. Install a pinned Allure CLI version (2.28.0)
      5. Setup Python 3.13
      6. Install dependencies
      7. Run make all (tests + Allure generation)
      8. Upload the allure-report folder as an artifact

What Changed

1. Test Reporting

  • scripts/allure_helper.py
    • CLI for cleaning, generating, and optionally serving the Allure report
    • Uses argparse for --results-dir, --report-dir, and --serve flags
    • Structured logging for each step
  • Integration in Makefile
    • serve-report invokes the helper script
    • report target auto-generates the HTML report

2. Centralized Logging

  • src\api_testing_framework/logger.py

    import logging
        
    logging.basicConfig(
        level=logging.INFO,
        format="%(asctime)s [%(levelname)s] %(name)s: %(message)s",
        datefmt="%Y-%m-%d %H:%M:%S"
    )
    logger = logging.getLogger("api_testing_framework")
  • Usage

    from api_testing_framework.logger import logger
    
    logger.info("Message")

3. Makefile

.PHONY: install test report serve-report clean all

install:
    poetry install --no-root

test:
    pytest

report:
    pytest --alluredir=allure-results
    allure generate allure-results --clean -o allure-report

serve-report:
    python scripts/allure_helper.py --serve

clean:
    rm -rf .pytest_cache/ allure-results/ allure-report/

all: clean install test report

4. CI Integration (.github/workflows/ci.yml)

name: Continuous Integration

on:
  push:         # on every push to main
    branches: [main]
  pull_request: # on PRs against main
    branches: [main]
  workflow_dispatch:

jobs:
  test-reporting:
    name: Test & Report
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      - name: Cache Poetry
        uses: actions/cache@v3
        with:
          path: ~/.cache/pypoetry
          key: ${{ runner.os }}-poetry-${{ hashFiles('**/poetry.lock') }}
          restore-keys: |
            ${{ runner.os }}-poetry-

      - name: Set up Java (Allure)
        uses: actions/setup-java@v3
        with:
          distribution: temurin
          java-version: '11'

      - name: Install Allure CLI
        run: |
          set -eux
          ALLURE_VERSION=2.28.0
          curl -Lo allure-commandline.zip \
            https://repo.maven.apache.org/maven2/io/qameta/allure/allure-commandline/${ALLURE_VERSION}/allure-commandline-${ALLURE_VERSION}.zip
          unzip -o allure-commandline.zip -d allure-cli
          echo "${PWD}/allure-cli/allure-${ALLURE_VERSION}/bin" >> $GITHUB_PATH

      - uses: actions/setup-python@v4
        name: Setup Python 3.13
        with:
          python-version: '3.13'

      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          python -m pip install poetry
          make install

      - name: Run tests and generate Allure report
        run: make all

      - name: Upload Allure Report artifact
        uses: actions/upload-artifact@v3
        with:
          name: allure-report
          path: ./allure-report

How to Verify Locally

# Install deps
make install

# Run unit tests
make test

# Generate report
make report

# Serve interactive report
make serve-report

Open allure-report/index.html in your browser.

@sethorpe sethorpe merged commit 6797992 into main May 30, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant