A comprehensive REST API testing framework demonstrating professional testing practices with Python, pytest, and Docker. Features automated testing with Allure reporting and CI/CD integration.
- β API Test Automation - Tests for GoRest and Football-Data APIs
- π³ Docker Support - Fully containerized test execution
- π Allure Reports - Beautiful test reports with history and trends
- π CI/CD Integration - Automated testing with GitHub Actions
- π― Performance Testing - Load testing with Locust
- ποΈ Clean Architecture - Reusable API clients with proper separation of concerns
- π§ Environment Management - Support for multiple test environments
- π Type Safety - Pydantic models for request/response validation
- Python 3.14 - Latest Python version
- pytest - Test framework
- uv - Dependency management
- Ruff - Linting and formatting
- Docker & Docker Compose - Containerization
- Allure - Test reporting
- Locust - Performance testing
- httpx - Modern HTTP client
- Pydantic - Data validation
- Faker - Test data generation
Choose one of the following setups:
- Python 3.11+ (3.14 recommended)
- uv
- Clone the repository:
git clone https://github.com/amazpyel/python_rest_api_testing
cd python_rest_api_testing- Copy environment file:
cp .env.example .env- Add your API tokens to
.env:
GOREST_TOKEN=your_gorest_token_here
FOOTBALL_DATA_TOKEN=your_football_data_token_hereGet tokens from:
- GoRest: https://gorest.co.in/
- Football-Data: https://www.football-data.org/
-
Clone and navigate to the repository
-
Install dependencies:
uv sync- Configure environment variables (same as Docker setup)
Run all tests:
docker compose run testRun specific test file:
docker compose run test tests/gorest_api/test_end_to_end.pyRun with markers:
docker compose run test -m "smoke"
docker compose run test -m "not destructive"Run performance tests:
docker compose up performance
# Access Locust UI at http://localhost:8089Run all tests:
uv run pytestRun with Allure results:
uv run pytest --alluredir=allure-resultsRun specific markers:
uv run pytest -m smokeStart Allure service:
docker compose up -d allureRun tests:
docker compose run testView reports: Open http://localhost:5050/allure-docker-service/latest-report
Reports include:
- β Test results with detailed steps
- π Historical trends and comparisons
- β±οΈ Duration trends
- π Retry and flaky test detection
- π Environment information
Stop Allure service:
docker compose downAutomated reports are published to GitHub Pages on every push:
- URL:
https://<username>.github.io/<repository-name>/ - Auto-updated on every CI run
- Historical data preserved across builds
Configure via .env file:
# Required: API Tokens
GOREST_TOKEN=your_token_here
FOOTBALL_DATA_TOKEN=your_token_here
# Test Environment (dev, staging, production)
TEST_ENV=production
# Optional: Allure Report Configuration
REPORT_NAME=REST API Test Suite
BUILD_NUMBER=1
EXECUTOR_NAME=pytest
EXECUTOR_TYPE=pytestAvailable pytest markers:
smoke- Quick smoke testsdestructive- Tests that modify datanegative- Negative test casesend2end- End-to-end test scenarios
Example:
# Run only smoke tests
docker compose run test -m smoke
# Skip destructive tests
docker compose run test -m "not destructive".
βββ src/
β βββ rest_api_client/ # Reusable API clients
β βββ base_client.py # Base HTTP client
β βββ gorest_api/ # GoRest API client
β βββ football_api/ # Football-Data API client
βββ tests/
β βββ conftest.py # Pytest configuration & fixtures
β βββ factories/ # Test data factories
β βββ gorest_api/ # GoRest API tests
β βββ football_api/ # Football-Data API tests
βββ performance/
β βββ locustfile.py # Load testing scenarios
βββ .github/
β βββ workflows/
β βββ tests.yml # CI/CD pipeline
βββ docker-compose.yml # Docker services configuration
βββ Dockerfile # Test container image
βββ pyproject.toml # Project config & dependencies
βββ uv.lock # Dependency lockfile
βββ README.md # This file
The project includes automated CI/CD that:
- β Runs tests on every push/PR
- π Generates Allure reports
- π Deploys reports to GitHub Pages
- π Shows test summary in Actions
- π Preserves historical data
-
Add Repository Secrets:
- Go to Settings β Secrets β Actions
- Add
GOREST_TOKEN - Add
FOOTBALL_DATA_TOKEN
-
Enable GitHub Pages:
- Go to Settings β Pages
- Source: Deploy from branch
- Branch:
gh-pages - Folder:
/(root)
-
Push to trigger:
git push origin main- View results:
- Actions tab: See test execution
- Pages URL: View Allure reports
- Environment Detection - Automatically detects CI vs Local execution
- Test Continuation - Workflow succeeds even if some tests fail
- Historical Trends - Preserves Allure history across runs
- Dynamic Build Info - Links back to GitHub Actions run
- Summary Report - Shows test status in Actions summary
- Create test file in appropriate directory
- Use existing fixtures (
gorest_client,football_api_client) - Add Allure annotations for better reporting
- Mark with appropriate pytest markers
Example:
import allure
import pytest
@pytest.mark.smoke
@allure.feature("User Management")
@allure.story("Get Users")
def test_get_users(gorest_client):
with allure.step("Fetch all users"):
users = gorest_client.get_users()
assert len(users) > 0- Create client in
src/rest_api_client/<api_name>/ - Extend
BaseRestApiClient - Define Pydantic models for validation
- Add pytest fixture in
tests/conftest.py
Tests fail in CI but pass locally:
- Check if API blocks CI/CD IPs (CloudFlare protection)
- Verify environment variables are set in GitHub Secrets
- Review the execution location in Allure reports
Docker build fails:
- Ensure Docker daemon is running
- Clear Docker cache:
docker compose build --no-cache - Check Docker disk space
Allure reports show "DEFAULT":
- Verify
REPORT_NAMEenvironment variable is set - Check
tests/conftest.pyexecutor configuration
No history in Allure reports:
- First run won't have history (expected)
- History builds after 2+ test runs
- Check
gh-pagesbranch exists
This project is for educational and portfolio purposes.
This is a portfolio project demonstrating testing skills. Feel free to use as reference or template for your own projects.
For questions or feedback, please open an issue in the repository.