A comprehensive test automation framework built with Python and pytest, designed for API, UI, database, and integration testing.
python-pytest-framework/
├── .github/workflows/ # GitHub Actions CI/CD workflows
│ ├── smoke.yml # Smoke test pipeline
│ ├── regression.yml # Regression test pipeline
│ └── nightly.yml # Nightly test suite
├── config/ # Configuration files
│ ├── config.yaml # Base configuration
│ ├── dev.yaml # Development environment
│ ├── qa.yaml # QA environment
│ ├── stage.yaml # Staging environment
│ └── prod.yaml # Production environment
├── core/ # Core framework modules
│ ├── api/ # API client utilities
│ ├── ui/ # UI automation utilities
│ ├── db/ # Database utilities
│ ├── auth/ # Authentication helpers
│ ├── drivers/ # WebDriver management
│ ├── clients/ # HTTP clients
│ ├── logger/ # Logging utilities
│ └── reporting/ # Report generation
├── pages/ # Page Object Model classes
├── api/ # API endpoint definitions
├── database/ # Database models and queries
├── utilities/ # Helper utilities
├── fixtures/ # Pytest fixtures
├── testdata/ # Test data files
├── schemas/ # JSON/API schemas
├── tests/ # Test suites
│ ├── api/ # API tests
│ ├── ui/ # UI tests
│ ├── db/ # Database tests
│ ├── integration/ # Integration tests
│ ├── contract/ # Contract tests
│ ├── performance/ # Performance tests
│ └── security/ # Security tests
├── reports/ # Test reports
├── screenshots/ # Test screenshots
├── logs/ # Test logs
├── Dockerfile # Docker image definition
├── docker-compose.yml # Docker Compose setup
├── requirements.txt # Python dependencies
├── pytest.ini # Pytest configuration
├── conftest.py # Pytest configuration hooks
└── README.md # Project documentation
- Python 3.11+
- pip or conda
- Docker and Docker Compose (optional)
- Clone the repository:
git clone <repository-url>
cd python-pytest-framework- Create a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install dependencies:
pip install -r requirements.txt- Configure environment:
cp config/dev.yaml config/local.yaml
# Edit config/local.yaml as neededBuild and run using Docker Compose:
docker-compose up --buildpytest tests/ -vpytest tests/api/ -v # API tests
pytest tests/ui/ -v # UI tests
pytest tests/db/ -v # Database tests
pytest tests/integration/ -v # Integration testspytest -m smoke -v # Smoke tests
pytest -m regression -v # Regression tests
pytest -m api -v # API tests
pytest -m ui -v # UI testspytest tests/ --cov=. --cov-report=htmlpytest tests/ --env=qa -v
pytest tests/ --env=prod -vpytest tests/ -n auto- Smoke Tests: Quick validation tests that run frequently
- Regression Tests: Comprehensive tests ensuring no functionality breaks
- API Tests: Tests for REST/GraphQL endpoints
- UI Tests: Browser-based UI automation tests
- Database Tests: Database integration and query tests
- Integration Tests: Multi-component integration tests
- Contract Tests: API contract validation tests
- Performance Tests: Load and performance testing
- Security Tests: Security vulnerability scanning
Configuration is environment-specific:
config/config.yaml: Base configurationconfig/dev.yaml: Development settingsconfig/qa.yaml: QA environment settingsconfig/stage.yaml: Staging environment settingsconfig/prod.yaml: Production environment settings
Load configuration in tests using the env_config fixture:
def test_api_call(env_config):
base_url = env_config['api']['base_url']
# Test code hereThe framework includes GitHub Actions workflows:
- smoke.yml: Runs smoke tests on push and pull requests
- regression.yml: Runs regression tests daily
- nightly.yml: Runs complete test suite nightly
- Logs are saved to
logs/directory - Test reports are generated in
reports/directory - Screenshots are captured in
screenshots/directory on failures - HTML reports are generated using
pytest-html - Allure reports are available using
allure-pytest
- Page Object Model: Use page objects for UI tests (see
pages/) - Test Data: Keep test data in
testdata/directory - Fixtures: Use pytest fixtures defined in
fixtures/ - Markers: Tag tests appropriately for selective execution
- Logging: Use core logger for consistent logging
- Error Handling: Capture screenshots on UI test failures
- Documentation: Add docstrings to test functions
- Module not found: Ensure virtual environment is activated
- WebDriver issues: Update browser drivers in
core/drivers/ - Database connection: Verify database configuration in
config/ - Test failures: Check logs in
logs/and screenshots inscreenshots/
- Create a feature branch
- Write tests for new functionality
- Ensure all tests pass locally
- Submit a pull request
MIT License - see LICENSE file for details