我有一个使用pipenv来运行pytest的Python项目。我想创建一个GitHub Action,每次提交请求时都会运行pytest。
我尝试使用python-app.yml入门工作流程。
name: Python application
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Set up Python 3.8
uses: actions/setup-python@v1
with:
python-version: 3.8
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Lint with flake8
run: |
pip install flake8
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pip install pytest
pytest
但是我遇到以下构建失败。
ERROR: Could not open requirements file: [Errno 2] No such file or directory: 'requirements.txt'
##[error]Process completed with exit code 1.
我想避免创建requirements.txt
,而只是使用pipenv运行pytest。
如何创建一个使用pipenv运行pytest的GitHub Action?
答案 0 :(得分:1)
使用Install pipenv GitHub Action。
例如:
name: Python application
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Set up Python 3.7
uses: actions/setup-python@v1
with:
python-version: 3.7
- name: Install pipenv
uses: dschep/install-pipenv-action@v1
- name: Install dependencies
run: |
pipenv install --dev
- name: Test with pytest
run: |
pipenv run pytest
答案 1 :(得分:0)
我只想补充一点,在使用 pipenv 和 pytest 时,我也遇到了 FileNotFoundError:
使用 pipenv run pytest
时,我在每个项目文件中都包含错误(您可以在此处查看日志:https://github.com/johannesgrothe/Smarthome_Bridge/runs/3080772118)
我需要的是使用pipenv run python -m pytest
,现在一切都像魅力一样(https://github.com/johannesgrothe/Smarthome_Bridge/runs/3098788625)。我需要很多pipenv库,所以肯定是使用pipenv python实例。
我相信这两个命令的作用完全相同,我不知道为什么第一个不起作用,而后者却起作用。
因为我花了很多时间来弄明白这个问题,所以我认为分享它会使其他人受益,我希望这是合适的地方。