1.目前,我正在构建一个flask项目,我也写了一些单元测试代码。现在我想在 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
最佳答案
您可以使用 nohup
命令在后台运行 flask 服务器,而不是在不同的终端上运行。
nohup python app.py
使用 sleep
运行此命令后等待一段时间命令,然后运行您的测试。
关于flask - 是否可以在 Github 操作的不同终端上运行命令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67645636/