在 Github Actions 中的 docker 组合服务上运行 pytest 时显示“进程已完成,退出代码为 137”

问题描述 投票:0回答:1

我已经为 Github Actions 创建了一个工作流程,以使用 pytest 自动执行测试。在 GitHub 上运行时,出现错误。


我遇到了错误形式的问题:

Process completed with exit code 137. 

在我的 Github Actions 工作流程中运行命令后:

docker compose -f testing.yaml exec api pytest

出现问题仅在 GitHub 上运行,本地使用 ACT - 一切正常。


.github/workflows/checks.yml

name: CI

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

env:
  // setup envs from secrets


jobs:
  linting-and-formatting:
    name: Linting and Formatting
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: api

    steps:
      - name: Checkout of the repository
        uses: actions/checkout@v4

      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: '3.12'

      - name: Create and activate virtual environment
        run: |
          python -m venv .venv
          source .venv/bin/activate

      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install -r requirements/development.txt

      - name: Check formatting with Black
        run: black --check --diff .

      - name: Linting with Flake8
        run: flake8 .

  testing:
    needs: linting-and-formatting

    name: Testing
    runs-on: ubuntu-latest

    steps:
        - name: Checkout of the repository
          uses: actions/checkout@v4

        - uses: hoverkraft-tech/[email protected]
          with:
            compose-file: "testing.yaml"
        
        - name: Execute tests in the running services
          run: |
            docker compose -f testing.yaml exec api pytest  //Here there is an error 137

我在网上搜索了一下,可能是与OOM相关的错误。


您知道这种情况的解决办法吗?

github docker-compose continuous-integration github-actions pytest
1个回答
0
投票

我发现问题了。

与OOM没有直接关系。添加后:

- name: Display container logs if tests fail
  if: failure()
    run: |
      docker compose -f testing.yaml logs

我得到信息说超级用户创建失败,这是错误初始化环境变量的错误。更改后,测试正确通过。

© www.soinside.com 2019 - 2024. All rights reserved.