How wintests/pytestdemo works
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).