# wintests/pytestdemo architecture

> Architecture diagram of the GitHub repository wintests/pytestdemo, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/wintests/pytestdemo
- Repository: https://github.com/wintests/pytestdemo

## Overview

##### Project type and purpose
- This is a Python-based API testing automation framework.
- Purpose: wrap HTTP endpoints as Python functions, compose them into business-level keywords, drive tests with Pytest and YAML data, and generate Allure reports.

##### File structure
- Top-level modules:
- api/             – HTTP interface wrappers
- common/          – utility classes (logging, MySQL, data reading)
- core/            – REST client (request engine) and result handling
- operation/       – business-level keywords invoking api/ methods
- config/          – configuration file (setting.ini)
- data/            – YAML files holding test data
- testcases/       – Pytest test suites (api_test and scenario_test)
- pytest.ini       – Pytest configuration
- requirements.txt – external dependencies
- Pattern: layered architecture with clear separation of interface, core engine, keyword, data, and test execution layers.

##### README for additional insights
- Confirms the layered breakdown (interface → keywords → testcases).
- Emphasizes data-driven (YAML) and keyword-driven approaches.
- Notes integration points: Pytest runner, Allure for reporting, optional Jenkins CI.

a. Main components
1. Test Runner (Pytest + pytest.ini)
2. Test Cases (testcases/api_test, testcases/scenario_test)
3. Keyword Layer (operation/)
4. API Wrapper Layer (api/)
5. Core Engine (core/rest_client.py, core/result_base.py)
6. Utilities (common/logger.py, common/mysql_operate.py, common/read_data.py)
7. Configuration (config/setting.ini)
8. Data Store (data/*.yml)
9. External System Under Test (e.g., FlaskDemo API)
10. Reporting & CI Tools (Allure, Jenkins)

b. Relationships & data flow
- The Test Runner loads testcases →
- Testcases read test data from YAML via common/read_data →
- Testcases invoke business keywords in operation/ →
- Keywords call API wrappers in api/ →
- API wrappers use core/rest_client to issue HTTP requests to the System Under Test →
- HTTP responses flow back through core/result_base to keywords →
- Keywords return structured results to testcases →
- Pytest collects pass/fail and writes raw data to report directory →
- Allure server reads raw data to generate HTML report →
- Optionally, Jenkins schedules pytest runs and publishes Allure results.

c. Architectural patterns and principles
- Layered modular architecture (separation of concerns)
- Keyword-driven testing
- Data-driven testing
- Dependency injection via Pytest fixtures (conftest.py)
- Single-responsibility modules

d. Key technologies & frameworks
- Python 3.x
- requests (HTTP client)
- Pytest (test execution)
- PyYAML (test data)
- Allure (reporting)
- configparser (configuration)
- logging (built-in)
- mysql-connector or pymysql (DB utilities)

##### Detail
- Break out subcomponents (e.g., rest_client vs. result_base) if space allows.
- Conftest.py fixtures injecting configuration or clients into testcases.
- Call out the config/setting.ini as the single source of environment variables (base URL, credentials).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Code Layers
    subgraph "Test Execution Layer"
        direction TB
        TR["Test Runner (pytest.ini)"]:::code
        click TR "https://github.com/wintests/pytestdemo/blob/master/pytest.ini"
        subgraph "Test Cases"
            direction TB
            subgraph "API Tests"
                direction TB
                API_CT["conftest.py"]:::code
                click API_CT "https://github.com/wintests/pytestdemo/blob/master/testcases/api_test/conftest.py"
                T1["test_01_get_user_info.py"]:::code
                click T1 "https://github.com/wintests/pytestdemo/blob/master/testcases/api_test/test_01_get_user_info.py"
                T2["test_02_register.py"]:::code
                click T2 "https://github.com/wintests/pytestdemo/blob/master/testcases/api_test/test_02_register.py"
                T3["test_03_login.py"]:::code
                click T3 "https://github.com/wintests/pytestdemo/blob/master/testcases/api_test/test_03_login.py"
                T4["test_04_update_user.py"]:::code
                click T4 "https://github.com/wintests/pytestdemo/blob/master/testcases/api_test/test_04_update_user.py"
                T5["test_05_delete_user.py"]:::code
                click T5 "https://github.com/wintests/pytestdemo/blob/master/testcases/api_test/test_05_delete_user.py"
            end
            subgraph "Scenario Tests"
                direction TB
                SC_CT["conftest.py"]:::code
                click SC_CT "https://github.com/wintests/pytestdemo/blob/master/testcases/scenario_test/conftest.py"
                S1["test_01_register_login_list.py"]:::code
                click S1 "https://github.com/wintests/pytestdemo/blob/master/testcases/scenario_test/test_01_register_login_list.py"
                S2["test_02_register_login_update.py"]:::code
                click S2 "https://github.com/wintests/pytestdemo/blob/master/testcases/scenario_test/test_02_register_login_update.py"
                S3["test_03_register_login_delete.py"]:::code
                click S3 "https://github.com/wintests/pytestdemo/blob/master/testcases/scenario_test/test_03_register_login_delete.py"
                S4["test_04_repeat_register.py"]:::code
                click S4 "https://github.com/wintests/pytestdemo/blob/master/testcases/scenario_test/test_04_repeat_register.py"
            end
        end
    end

    subgraph "Keyword Layer"
        direction TB
        KW["Business Keywords (operation/user.py)"]:::code
        click KW "https://github.com/wintests/pytestdemo/blob/master/operation/user.py"
    end

    subgraph "API Wrapper Layer"
        direction TB
        API["HTTP Interface (api/user.py)"]:::code
        click API "https://github.com/wintests/pytestdemo/blob/master/api/user.py"
    end

    subgraph "Core Engine"
        direction TB
        RC["REST Client (core/rest_client.py)"]:::code
        click RC "https://github.com/wintests/pytestdemo/blob/master/core/rest_client.py"
        RB["Result Handler (core/result_base.py)"]:::code
        click RB "https://github.com/wintests/pytestdemo/blob/master/core/result_base.py"
    end

    subgraph "Utilities" 
        direction TB
        LOG["Logger (common/logger.py)"]:::code
        click LOG "https://github.com/wintests/pytestdemo/blob/master/common/logger.py"
        SQL["MySQL Operate (common/mysql_operate.py)"]:::code
        click SQL "https://github.com/wintests/pytestdemo/blob/master/common/mysql_operate.py"
        RD["Data Reader (common/read_data.py)"]:::code
        click RD "https://github.com/wintests/pytestdemo/blob/master/common/read_data.py"
    end

    subgraph "Configuration & Data" 
        direction TB
        CFG["Config (config/setting.ini)"]:::data
        click CFG "https://github.com/wintests/pytestdemo/blob/master/config/setting.ini"
        subgraph "YAML Data Store"
            direction TB
            D1["api_test_data.yml"]:::data
            click D1 "https://github.com/wintests/pytestdemo/blob/master/data/api_test_data.yml"
            D2["base_data.yml"]:::data
            click D2 "https://github.com/wintests/pytestdemo/blob/master/data/base_data.yml"
            D3["scenario_test_data.yml"]:::data
            click D3 "https://github.com/wintests/pytestdemo/blob/master/data/scenario_test_data.yml"
        end
    end

    %% External Systems
    SUT["System Under Test"]:::external
    ALLURE["Allure Reporting"]:::external
    JENKINS["Jenkins CI"]:::external
    REQ["Dependencies (requirements.txt)"]:::code
    click REQ "https://github.com/wintests/pytestdemo/blob/master/requirements.txt"

    %% Data & Configuration flow
    TR -->|loads| API_CT
    API_CT -->|reads YAML| RD
    SC_CT -->|reads YAML| RD
    RD -->|fetches data| D1
    RD -->|fetches data| D2
    RD -->|fetches data| D3
    CFG -->|provides settings| RC

    %% Test to Keywords flow
    API_CT -->|calls| KW
    T1 -->|calls| KW
    T2 -->|calls| KW
    T3 -->|calls| KW
    T4 -->|calls| KW
    T5 -->|calls| KW
    S1 -->|calls| KW
    S2 -->|calls| KW
    S3 -->|calls| KW
    S4 -->|calls| KW

    %% Keyword to API flow
    KW -->|invokes| API

    %% API to Core flow
    API -->|uses| RC
    RC -->|HTTP request| SUT
    SUT -->|HTTP response| RB
    RB -->|structures result| KW
    KW -->|returns data| API_CT
    KW -->|returns data| SC_CT

    %% Reporting & CI
    TR -->|generates| ALLURE
    JENKINS -->|triggers| TR
    JENKINS -->|publishes| ALLURE

    %% Styles
    classDef codeLayers fill:#cce5ff,stroke:#333,stroke-width:1px
    classDef code fill:#cce5ff
    classDef data fill:#d4edda
    classDef external fill:#ffe5b4
    classDef codeLayers fill:#cce5ff
    class TR,API_CT,T1,T2,T3,T4,T5,SC_CT,S1,S2,S3,S4,KW,API,RC,RB,LOG,SQL,RD,REQ code
    class CFG,D1,D2,D3 data
    class SUT,ALLURE,JENKINS external
```
