This is a REST API test automation framework built using Python, Requests, and Pytest.
The framework uses the ReqRes public API for demonstration purposes and showcases real-world API automation practices used in professional QA and SDET teams, including client abstraction, dynamic test data generation, schema validation, structured logging, environment management, and rich reporting.
Although ReqRes is used as the target API, the framework architecture is designed to be reusable and scalable for real-world REST API testing projects.
This project was built as part of my QA Automation learning journey and portfolio development.
| Tool | Purpose |
|---|---|
| Python | Core programming language |
| Requests | HTTP client for API interactions |
| Pytest | Test runner and framework |
| Allure | Rich test reporting |
| Faker | Dynamic test data generation |
| jsonschema | Response schema validation |
| python-dotenv | Environment configuration management |
| Logging | Request and response logging |
| GitHub Actions | Continuous Integration (CI/CD) |
- Full CRUD coverage (GET, POST, PUT, PATCH, DELETE)
- Positive and negative test scenarios
- Pagination testing
- API Client Pattern implementation
- Session reuse using
requests.Session() - Dynamic test data generation using Faker
- JSON Schema validation
- Structured request and response logging
- Environment configuration using
.env - Allure reporting with rich attachments
- Pytest markers for test categorization
- GitHub Actions CI/CD integration
api-python-framework/
│
├── api_clients/
│ ├── base_client.py
│ └── users_client.py
│
├── config/
│ └── config.py
│
├── payloads/
│ ├── create_user_payload.py
│ ├── update_user_payload.py
│ └── patch_user_payload.py
│
├── schemas/
│ └── user_schema.json
│
├── tests/
│ ├── test_users.py
│ ├── test_create_user.py
│ ├── test_update_user.py
│ ├── test_delete_user.py
│ ├── test_users_negative.py
│ └── test_users_pagination.py
│
├── utils/
│ ├── allure_helper.py
│ ├── data_generator.py
│ ├── logger.py
│ └── validator.py
│
├── reports/
│ ├── logs/
│ └── allure-results/
│
├── conftest.py
├── .env.example
├── requirements.txt
├── pytest.ini
└── README.md
The framework follows the API Client Pattern, similar to the Page Object Model (POM) used in UI automation.
LoginPage
InventoryPage
CartPage
AuthClient
UsersClient
ProductsClient
Each client is responsible for interacting with a specific group of endpoints, resulting in cleaner and more maintainable test code.
The framework uses requests.Session() through the BaseClient to:
- Reuse TCP connections
- Improve execution performance
- Centralize authentication headers
- Reduce duplicate code
- Simplify client maintenance
git clone https://github.com/unaisWorks/api-python-framework.git
cd api-python-frameworkpython3 -m venv venv
source venv/bin/activatepython -m venv venv
venv\Scripts\activatepip install -r requirements.txtCopy the example file:
cp .env.example .envUpdate the values:
BASE_URL=https://reqres.in/api
API_KEY=your_reqres_api_keypytest -vpytest -m smokepytest -m regressionpytest -m apiGenerate Allure results:
pytest --alluredir=reports/allure-resultsServe the report:
allure serve reports/allure-resultsInstall Allure CLI:
brew install allureDownload and install from the official Allure website.
- Test results grouped by feature
- Severity classifications
- Request payload attachments
- Response body attachments
- Step-level execution visibility
- Easier failure investigation
GitHub Actions is used to automate test execution.
Current capabilities include:
- Running tests on push events
- Running tests on pull requests
- Generating Allure results
- Uploading test artifacts
- Providing fast feedback on API quality
| Variable | Description |
|---|---|
| BASE_URL | Base URL of the API |
| API_KEY | API authentication key |
Refer to .env.example for configuration guidance.
This framework demonstrates:
- Building a scalable API automation framework from scratch
- Applying the API Client Pattern
- Separating concerns across clients, payloads, utilities, and tests
- Managing environments using
.env - Implementing schema validation
- Generating dynamic test data
- Producing actionable Allure reports
- Writing maintainable and reusable automation code
- Applying industry-standard QA automation practices
Planned improvements include:
- Docker support
- Parallel execution using
pytest-xdist - Retry mechanisms for unstable endpoints
- OAuth 2.0 authentication flows
- Database validation
- Contract testing
- Performance testing integration
Mohamed Unais
LinkedIn: https://www.linkedin.com/in/unaisvds/
GitHub: https://github.com/unaisWorks
This framework represents my transition from UI Automation to API Automation as part of my journey toward becoming an industry-ready QA Automation Engineer/SDET.
It builds upon my previous experience developing Selenium frameworks with Page Object Model, Allure Reporting, Logging, GitHub, and GitHub Actions, while expanding into professional API testing practices used in modern software teams.