Skip to content

Framework for automating LearnQA API testing using Python and Pytest

Notifications You must be signed in to change notification settings

vypiemzalyubov/test-automation-rest-api

Repository files navigation

Test Automation REST API

Python Build

Framework for automating API testing from the course "Automating REST API testing in Python" by LearnQA

📌 Navigation

Description | Prerequisites | Project Structure | Project Setup | Running tests | Viewing reports | Github workflow

📌 Description:

  • Automated CRUD (POST, GET, PUT, DELETE) APIs using Python and Pytest
  • Continuous testing with GitHub Actions

📌 Prerequisites:

Pytest Requests JSON Schema Allure Pytest

📌 Project Structure:

test-automation-rest-api/
├─ .github/
│  ├─ workflows/
│  │  ├─ run_tests.yml
├─ lib
│  ├─ __init__.py/
│  ├─ assertions.py
│  ├─ base_case.py
│  ├─ logger.py
│  ├─ my_requests.py
│  ├─ schema.py
├─ logs 
├─ tests/
│  ├─ __init__.py
│  ├─ test_user_auth.py
│  ├─ test_user_delete.py
│  ├─ test_user_edit.py
│  ├─ test_user_get.py
│  ├─ test_user_register.py
├─ .gitignore
├─ Dockerfile
├─ README.md
├─ docker-compose.yml
├─ environment.py
├─ pytest.ini
├─ requirements.txt

📌 Project Setup

# Clone repository
git clone https://github.com/vypiemzalyubov/test-automation-rest-api.git

# Install virtual environment
python3 -m venv venv

# Activate virtual environment
source venv/bin/activate

# Install dependencies
pip install -r requirements.txt

📌 Running tests

# Run all tests
pytest tests/

# Run positive test cases
pytest -m "positive"

# Run negative test cases
pytest -m "negative"

# Run tests with "prod" environment (default "dev")
ENV=prod pytest tests/

Default startup options in pytest.ini:

addopts = 
       -s -v
       --alluredir=allure-results

📌 Running in Docker

# Build an image named "pytest-runner"
docker build -t pytest-runner .

# Launch the container
docker run pytest-runner

# Running with Docker Compose
docker-compose up --build

📌 Viewing reports

  • Install Allure from the official website

  • Generate Allure report

    allure serve

📌 Github workflow

  • Go to "Run workflow" in GitHub Actions

    # Options in workflow
      - all_tests
      - positive_tests
      - negative_tests
  • View Allure test results after completing the GitHub Actions workflow