Python-based API test automation framework using pytest, requests and JSON schema validation.
This project demonstrates how to build a reusable API testing framework with an object-oriented client layer, pytest fixtures, parametrized tests, schema validation, environment-based configuration and CI execution.
This project is created for QA automation practice, learning and portfolio demonstration purposes.
It uses the public JSONPlaceholder API, which provides fake REST endpoints for testing and prototyping. The project does not interact with private systems, production business data or confidential information.
Write operations such as POST, PUT, PATCH and DELETE are simulated by JSONPlaceholder and are not persisted.
The framework tests public REST API endpoints related to:
- posts
- users
- todos
- comments linked to posts
The project is structured as a small but realistic API automation framework, not just a collection of standalone tests.
- Python API test automation
- pytest-based test execution
- requests-based HTTP client
- object-oriented API client layer
- reusable pytest fixtures
- parametrized tests
- JSON schema validation
- reusable assertion utilities
- environment-based configuration
- HTML report generation
- GitHub Actions CI workflow
- Python
- pytest
- requests
- jsonschema
- pytest-html
- python-dotenv
- GitHub Actions
Base URL:
https://jsonplaceholder.typicode.com
Tested resources:
/posts
/posts/{id}
/posts/{id}/comments
/users
/users/{id}
/todos
/todos/{id}
python-api-test-automation-framework
├── api
│ ├── base_client.py
│ ├── posts_client.py
│ ├── todos_client.py
│ └── users_client.py
├── config
│ └── settings.py
├── schemas
│ ├── post_schema.json
│ ├── todo_schema.json
│ └── user_schema.json
├── tests
│ ├── conftest.py
│ ├── test_posts.py
│ ├── test_todos.py
│ └── test_users.py
├── utils
│ ├── assertions.py
│ └── schema_validator.py
├── .github
│ └── workflows
│ └── python-tests.yml
├── .env.example
├── .gitignore
├── pytest.ini
├── requirements.txt
└── README.md
The framework uses an object-oriented API client layer.
BaseApiClient contains reusable HTTP methods:
GET
POST
PUT
PATCH
DELETE
Domain-specific clients extend the base client:
PostsClient
UsersClient
TodosClient
This keeps the tests clean and avoids direct requests calls inside test cases.
Reusable pytest fixtures are defined in tests/conftest.py.
They provide:
- posts client
- users client
- todos client
- sample request payloads
JSON schema files are stored under the schemas/ folder.
The framework validates API responses against schemas for:
- posts
- users
- todos
Reusable assertion helpers are stored in utils/assertions.py.
They support:
- status code validation
- required key validation
- non-empty list validation
The current version includes 19 passing tests.
Covered scenarios include:
GET all posts
GET post by ID
GET comments for a post
POST create post
PUT update post
PATCH update post
DELETE post
GET all users
GET user by ID
Validate user email format
GET all todos
GET todo by ID
Validate todo completed field type
Create and activate a virtual environment:
python -m venv .venvWindows PowerShell:
.\.venv\Scripts\Activate.ps1Install dependencies:
python -m pip install --upgrade pip
python -m pip install -r requirements.txtRun all tests:
python -m pytestRun tests with verbose output:
python -m pytest -vRun smoke tests:
python -m pytest -m smokeGenerate an HTML report:
python -m pytest --html=reports/report.html --self-contained-htmlCurrent local execution result:
19 passed
Default configuration is stored in config/settings.py.
The framework also supports environment variables through .env.
Example .env values:
BASE_URL=https://jsonplaceholder.typicode.com
API_TIMEOUT=10The project includes a GitHub Actions workflow that installs dependencies and runs the API test suite on push and pull request events.
Workflow file:
.github/workflows/python-tests.yml
This project demonstrates:
- Python test automation
- API testing
- pytest fixtures
- pytest parametrization
- requests-based HTTP testing
- object-oriented test framework design
- JSON schema validation
- reusable assertions
- environment configuration
- HTML test reporting
- GitHub Actions CI
- practical SDET mindset
Current limitations:
- public API availability may affect test execution
- write operations are simulated and not persisted
- no advanced logging yet
- no Allure reporting yet
- no negative contract testing yet
- no authentication scenarios yet
Possible next improvements:
- add negative API scenarios
- add authentication examples using a different demo API
- add response time assertions
- add Allure reporting
- add request/response logging
- add data-driven tests from JSON files
- add Pydantic models for response validation
- add more schema validation coverage
- add Docker support
Petar Nikolov
Test Automation Engineering Analyst with experience in ERP and banking systems, Java/Python automation, Selenium, API testing, Cucumber BDD, QA tooling, XML test data generation and business-critical software testing.