From 273640aaba1092c9cdf664a48005d669a0ffbcd1 Mon Sep 17 00:00:00 2001 From: Liears <87860465+Liears@users.noreply.github.com> Date: Thu, 29 Oct 2026 14:53:04 +0800 Subject: [PATCH] ci: run the backend test suite on push and pull request The repository only had a tag-triggered desktop build workflow, so nothing ever executed pytest. That is how a stale test file could abort collection and sixteen tests could stay red on main with nobody noticing. Add a Tests workflow (ubuntu + windows, Python 3.12) and declare the test dependencies in requirements-dev.txt: pytest and pytest-asyncio were not listed anywhere, so every contributor had to discover and install them by hand before the suite would even start. --- .github/workflows/tests.yml | 49 +++++++++++++++++++++++++++++++++++++ .gitignore | 2 ++ requirements-dev.txt | 5 ++++ 3 files changed, 56 insertions(+) create mode 100644 .github/workflows/tests.yml create mode 100644 requirements-dev.txt diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..d731756 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,49 @@ +name: Tests + +on: + push: + branches: + - main + pull_request: + workflow_dispatch: + +permissions: + contents: read + +jobs: + pytest: + name: pytest (${{ matrix.os }}, py${{ matrix.python }}) + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + # Windows 是桌面版的目标平台,POSIX 假设的回归必须在这里同样暴露 + include: + - os: ubuntu-latest + python: "3.12" + - os: windows-latest + python: "3.12" + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python }} + cache: pip + cache-dependency-path: | + requirements.txt + requirements-dev.txt + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements-dev.txt + + - name: Run tests + env: + # 中文断言与日志在 Windows 控制台默认代码页下会乱码 + PYTHONIOENCODING: utf-8 + run: python -m pytest tests -q diff --git a/.gitignore b/.gitignore index 1d2fddd..6d52631 100644 --- a/.gitignore +++ b/.gitignore @@ -95,6 +95,8 @@ data/workspace/ temp/ *.tmp *.txt +# 依赖清单是源码,不受上面的 *.txt 影响 +!requirements*.txt *.xlsx *.xls diff --git a/requirements-dev.txt b/requirements-dev.txt new file mode 100644 index 0000000..aa01d7a --- /dev/null +++ b/requirements-dev.txt @@ -0,0 +1,5 @@ +# 测试与开发期依赖;运行应用只需 requirements.txt +-r requirements.txt + +pytest>=8.0 +pytest-asyncio>=0.23