首页 > 解决方案 > 是否可以在 Github 操作的不同终端上运行命令?

问题描述

1.目前,我正在构建一个烧瓶项目,并且我还编写了一些单元测试代码。现在我想在 GitHub 操作上运行单元测试,但它卡在 ./run 阶段(./run 将打开http://127.0.0.1:5000/),并且不运行 $pytest命令。我知道 $pytest 不会执行的原因,因为 Github Action 正在运行端口 http://127.0.0.1:5000/。在这种情况下,它无法执行./run 之后的任何命令。我想知道我可以在 GitHub 操作中的另一个终端上运行 $pytest 吗?这可能吗?

这是我的 github 操作的输出:

Run cd Flask-backend
  cd Flask-backend
  ./run
  pytest 
  shell: /usr/bin/bash -e {0}
  env:
    pythonLocation: /opt/hostedtoolcache/Python/3.8.10/x64
 * Serving Flask app 'app.py' (lazy loading)
 * Environment: development
 * Debug mode: on
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 404-425-256

2.这是我的 yml 文件代码:

name: UnitTesting
on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Install Python 3
        uses: actions/setup-python@v1
        with:
          python-version: 3.8
      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install -r requirement.txt
          
      - name: Run tests with pytest
        run: |
           cd Flask-backend
           ./run
           pytest 

标签: flaskgithubgithub-actions

解决方案


您可以使用nohup命令在后台运行烧瓶服务器,而不是在不同的终端上运行。

nohup python app.py

使用命令运行此命令后等待一段时间sleep,然后运行测试。


推荐阅读