flask - 是否可以在 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
解决方案
您可以使用nohup
命令在后台运行烧瓶服务器,而不是在不同的终端上运行。
nohup python app.py
使用命令运行此命令后等待一段时间sleep
,然后运行测试。
推荐阅读
- pom.xml - 我在 pom.xml 的第一行得到红色 X 标记...我想知道原因
- sql-server - SSRS 多选和 For-Each 存储过程
- react-native - 如何将Unity游戏导出为React Native?
- reactjs - 对使用 Salesforce 作为 React 的用户身份验证平台有何想法?
- postgresql - PostgreSQL - 从数据库转储中恢复一个备份表
- c++ - C++:std::list 之间的区别
和 std::list<*type> - javascript - Vue路由器水平滚动到哈希不起作用
- c# - 在同一页面中实现登录和注册 AspNet Core 脚手架应用
- reactjs - ESLint 错误:React 中的“验证中缺少道具”(用 PropTypes.checkPropTypes 替换它不能解决它)?
- javascript - 运行 react-native run-android 后:解决依赖关系需要永远完成