# API接口测试 **Repository Path**: Accsen/api-interface-testing ## Basic Information - **Project Name**: API接口测试 - **Description**: API接口自动化测试 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-10-22 - **Last Updated**: 2026-03-17 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # API Interface Testing Project This project is an API automation testing framework based on Python + pytest, supporting parameterized testing, Fixture scope management, Allure report generation, JSON Schema validation, and YAML data reading/writing functionalities. ## Project Structure ``` API_Test/ ├── cases/ # Test case directory │ ├── test_case01.py # Basic test cases │ ├── test_case02.py # Setup/Teardown cases │ ├── test_case03.py # Parameterized testing (pytest.mark.parametrize) │ ├── test_case04.py # Fixture testing │ ├── test_case05.py # Class-level Fixture │ ├── test_case06.py # Mixed Fixture usage │ ├── test_case07.py # Additional test cases │ ├── test_case08.py # Parameterized Fixture │ ├── test_jsonschema.py # JSON Schema validation │ ├── test_yaml09.py # YAML file read/write │ └── case_01.py # Categorized test cases ├── tests/ # Additional test directory │ └── test_aaa.py ├── allure-report/ # Allure test reports ├── conftest.py # Global pytest configuration ├── my_logging.py # Logging module ├── requirement.txt # Project dependencies ├── pytest.ini # pytest configuration ├── firstYaml.yml # Test YAML file └── secondYaml.yml # Test YAML file ``` ## Features ### 1. Parameterized Testing Supports data-driven testing using `@pytest.mark.parametrize`: ```python @pytest.mark.parametrize("data", [1, 2, 3]) def test(data): ... @pytest.mark.parametrize("test_input, expected", [("3+5", 8), ("2+4", 6)]) def test_eval(test_input, expected): ... ``` ### 2. Fixture Scopes Supports multiple Fixture scopes: - `function`: Default scope; executed once per test function - `class`: Class-level; executed once per test class - `session`: Session-level; executed once per test session ```python @pytest.fixture(scope="class") def fixture_01(): ... ``` ### 3. JSON Schema Validation Uses JSON Schema to validate the structure and data types of API responses. ### 4. YAML Data Management Supports reading and writing test data in YAML format: ```python def write_yaml(data): ... def read_yaml(): ... ``` ### 5. Allure Reports Integrated with Allure to generate visual test reports: ```bash pytest --alluredir=./allure-result allure serve ./allure-result ``` ### 6. Logging Uses the custom logging module `my_logging.py` to record test execution details. ## System Requirements - Python 3.12+ - pytest 8.3.2 - Allure Report - PyYAML ## Install Dependencies ```bash pip install -r requirement.txt ``` ## Run Tests ### Run All Tests ```bash pytest ``` ### Run Specific Test File ```bash pytest cases/test_case03.py ``` ### Run Specific Test Case ```bash pytest cases/test_case03.py::test_data ``` ### Generate Allure Report ```bash pytest --alluredir=./allure-result allure serve ./allure-result ``` ### View Logs Test logs are recorded in the `mylog.log` file. ## Test Case Descriptions | File | Description | |------|-------------| | `test_case01.py` | Basic test cases | | `test_case02.py` | Demonstrates Setup and Teardown usage | | `test_case03.py` | Example of parameterized testing | | `test_case04.py` | Basic Fixture usage | | `test_case05.py` | Class-level Fixture | | `test_case06.py` | Mixed Fixture usage | | `test_case07.py` | Additional test scenarios | | `test_case08.py` | Parameterized Fixture | | `test_jsonschema.py` | JSON Schema validation example | | `test_yaml09.py` | YAML file read/write example | ## Configuration Files ### pytest.ini pytest runtime configuration including test paths and command-line options. ### requirement.txt List of project dependency packages: - pytest - allure-pytest - PyYAML - jsonschema - Other testing-related libraries ## Contribution Guidelines Pull Requests and Issues are welcome to enhance this testing framework. ## License This project is for learning and communication purposes only.