Pytest 失败退出代码 1,(github 操作)
Pytest fail exit code 1, (github actions)
我有一个 github 存储库,其中有一个文件 Test_app.py
。我 运行 在 github 操作中对文件进行 pytest,并不断收到错误消息:E botocore.exceptions.NoRegionError: You must specify a region.
然后我在文件中将区域指定为:dynamodb = boto3.resource('dynamodb', region_name= 'eu-west-2')
。当我执行 pytest 时出现以下错误:
platform win32 -- Python 3.8.6, pytest-6.2.0, py-1.10.0, pluggy-0.13.1
rootdir: D:\a\cloudresumechallenge-BackEnd\cloudresumechallenge-BackEnd
collected 0 items
============================ no tests ran in 0.31s ============================
Error: Process completed with exit code 1.
这是我的 lambda 代码:
import boto3
import json
dynamodb = boto3.resource('dynamodb', region_name= 'eu-west-2')
table= dynamodb.Table('zacresumetable2')
def lambda_handler(event, context):
response= table.update_item(
Key= {'URL': 'zacresume.com'},
UpdateExpression= "SET visits = visits + :increase",
ExpressionAttributeValues= {':increase': 1},
ReturnValues= "UPDATED_NEW"
)
return {'statusCode': 200,
'body': json.dumps('visitsUpdated'),
'headers': {'Content-Type': 'application/json'}}
print("UPDATING ITEM")
print("response")
这是 pytest 的工作流程:
name: Python package
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
runs-on: windows-latest
strategy:
matrix:
python-version: ['3.8']
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@main
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest
- name: Install boto3
run: pip3 install boto3
- name: Lint with flake8
run: |
# 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
文件夹结构
文件夹
-.aws-sam
- 建造
--build.toml
-samconfig.toml
-模板
-λ
- 要求
--Test_app
样本测试:
Requirement already satisfied: pytest in c:\hostedtoolcache\windows\python.8.6\x64\lib\site-packages (6.2.0)
Requirement already satisfied: toml in c:\hostedtoolcache\windows\python.8.6\x64\lib\site-packages (from pytest) (0.10.2)
Requirement already satisfied: attrs>=19.2.0 in c:\hostedtoolcache\windows\python.8.6\x64\lib\site-packages (from pytest) (20.3.0)
Requirement already satisfied: colorama in c:\hostedtoolcache\windows\python.8.6\x64\lib\site-packages (from pytest) (0.4.4)
Requirement already satisfied: iniconfig in c:\hostedtoolcache\windows\python.8.6\x64\lib\site-packages (from pytest) (1.1.1)
Requirement already satisfied: pluggy<1.0.0a1,>=0.12 in c:\hostedtoolcache\windows\python.8.6\x64\lib\site-packages (from pytest) (0.13.1)
Requirement already satisfied: packaging in c:\hostedtoolcache\windows\python.8.6\x64\lib\site-packages (from pytest) (20.8)
Requirement already satisfied: py>=1.8.2 in c:\hostedtoolcache\windows\python.8.6\x64\lib\site-packages (from pytest) (1.10.0)
Requirement already satisfied: atomicwrites>=1.0 in c:\hostedtoolcache\windows\python.8.6\x64\lib\site-packages (from pytest) (1.4.0)
Requirement already satisfied: pyparsing>=2.0.2 in c:\hostedtoolcache\windows\python.8.6\x64\lib\site-packages (from packaging->pytest) (2.4.7)
============================= test session starts =============================
platform win32 -- Python 3.8.6, pytest-6.2.0, py-1.10.0, pluggy-0.13.1
rootdir: D:\a\cloudresumechallenge-BackEnd\cloudresumechallenge-BackEnd
collected 0 items
============================ no tests ran in 0.31s ============================
Error: Process completed with exit code 1.```
首先,你应该确保你的测试用例从给定的数据开始 test_
在我看来你没有正确设置测试。例如,这是您应用的正确结构。
- 我的应用/
- run.py
- 测试/
- test_function_1.py
在 test_function_1.py
里面你应该有:
# Just for the sake of the example
def test_func_case_1():
assert True
def test_func_case_2():
assert 1 == 1
检查此代码并告诉我它是否对您有帮助。
我有一个 github 存储库,其中有一个文件 Test_app.py
。我 运行 在 github 操作中对文件进行 pytest,并不断收到错误消息:E botocore.exceptions.NoRegionError: You must specify a region.
然后我在文件中将区域指定为:dynamodb = boto3.resource('dynamodb', region_name= 'eu-west-2')
。当我执行 pytest 时出现以下错误:
platform win32 -- Python 3.8.6, pytest-6.2.0, py-1.10.0, pluggy-0.13.1
rootdir: D:\a\cloudresumechallenge-BackEnd\cloudresumechallenge-BackEnd
collected 0 items
============================ no tests ran in 0.31s ============================
Error: Process completed with exit code 1.
这是我的 lambda 代码:
import boto3
import json
dynamodb = boto3.resource('dynamodb', region_name= 'eu-west-2')
table= dynamodb.Table('zacresumetable2')
def lambda_handler(event, context):
response= table.update_item(
Key= {'URL': 'zacresume.com'},
UpdateExpression= "SET visits = visits + :increase",
ExpressionAttributeValues= {':increase': 1},
ReturnValues= "UPDATED_NEW"
)
return {'statusCode': 200,
'body': json.dumps('visitsUpdated'),
'headers': {'Content-Type': 'application/json'}}
print("UPDATING ITEM")
print("response")
这是 pytest 的工作流程:
name: Python package
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
runs-on: windows-latest
strategy:
matrix:
python-version: ['3.8']
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@main
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest
- name: Install boto3
run: pip3 install boto3
- name: Lint with flake8
run: |
# 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
文件夹结构
文件夹
-.aws-sam
- 建造
--build.toml
-samconfig.toml
-模板
-λ
- 要求
--Test_app
样本测试:
Requirement already satisfied: pytest in c:\hostedtoolcache\windows\python.8.6\x64\lib\site-packages (6.2.0)
Requirement already satisfied: toml in c:\hostedtoolcache\windows\python.8.6\x64\lib\site-packages (from pytest) (0.10.2)
Requirement already satisfied: attrs>=19.2.0 in c:\hostedtoolcache\windows\python.8.6\x64\lib\site-packages (from pytest) (20.3.0)
Requirement already satisfied: colorama in c:\hostedtoolcache\windows\python.8.6\x64\lib\site-packages (from pytest) (0.4.4)
Requirement already satisfied: iniconfig in c:\hostedtoolcache\windows\python.8.6\x64\lib\site-packages (from pytest) (1.1.1)
Requirement already satisfied: pluggy<1.0.0a1,>=0.12 in c:\hostedtoolcache\windows\python.8.6\x64\lib\site-packages (from pytest) (0.13.1)
Requirement already satisfied: packaging in c:\hostedtoolcache\windows\python.8.6\x64\lib\site-packages (from pytest) (20.8)
Requirement already satisfied: py>=1.8.2 in c:\hostedtoolcache\windows\python.8.6\x64\lib\site-packages (from pytest) (1.10.0)
Requirement already satisfied: atomicwrites>=1.0 in c:\hostedtoolcache\windows\python.8.6\x64\lib\site-packages (from pytest) (1.4.0)
Requirement already satisfied: pyparsing>=2.0.2 in c:\hostedtoolcache\windows\python.8.6\x64\lib\site-packages (from packaging->pytest) (2.4.7)
============================= test session starts =============================
platform win32 -- Python 3.8.6, pytest-6.2.0, py-1.10.0, pluggy-0.13.1
rootdir: D:\a\cloudresumechallenge-BackEnd\cloudresumechallenge-BackEnd
collected 0 items
============================ no tests ran in 0.31s ============================
Error: Process completed with exit code 1.```
首先,你应该确保你的测试用例从给定的数据开始 test_
在我看来你没有正确设置测试。例如,这是您应用的正确结构。
- 我的应用/
- run.py
- 测试/
- test_function_1.py
在 test_function_1.py
里面你应该有:
# Just for the sake of the example
def test_func_case_1():
assert True
def test_func_case_2():
assert 1 == 1
检查此代码并告诉我它是否对您有帮助。