我有一个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:acloudresumechallenge-BackEndcloudresumechallenge-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
文件夹结构SAMFOLDER-.aws sam--构建--build.toml-samconfig.toml-模板-λ--要求--Test_app
样本测试:
Requirement already satisfied: pytest in c:hostedtoolcachewindowspython3.8.6x64libsite-packages (6.2.0)
Requirement already satisfied: toml in c:hostedtoolcachewindowspython3.8.6x64libsite-packages (from pytest) (0.10.2)
Requirement already satisfied: attrs>=19.2.0 in c:hostedtoolcachewindowspython3.8.6x64libsite-packages (from pytest) (20.3.0)
Requirement already satisfied: colorama in c:hostedtoolcachewindowspython3.8.6x64libsite-packages (from pytest) (0.4.4)
Requirement already satisfied: iniconfig in c:hostedtoolcachewindowspython3.8.6x64libsite-packages (from pytest) (1.1.1)
Requirement already satisfied: pluggy<1.0.0a1,>=0.12 in c:hostedtoolcachewindowspython3.8.6x64libsite-packages (from pytest) (0.13.1)
Requirement already satisfied: packaging in c:hostedtoolcachewindowspython3.8.6x64libsite-packages (from pytest) (20.8)
Requirement already satisfied: py>=1.8.2 in c:hostedtoolcachewindowspython3.8.6x64libsite-packages (from pytest) (1.10.0)
Requirement already satisfied: atomicwrites>=1.0 in c:hostedtoolcachewindowspython3.8.6x64libsite-packages (from pytest) (1.4.0)
Requirement already satisfied: pyparsing>=2.0.2 in c:hostedtoolcachewindowspython3.8.6x64libsite-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:acloudresumechallenge-BackEndcloudresumechallenge-BackEnd
collected 0 items
============================ no tests ran in 0.31s ============================
Error: Process completed with exit code 1.```
首先,您应该确保您的测试用例从给定数据中的test_
开始——在我看来,您没有正确设置测试。例如,这是应用程序的正确结构。
- MyApp/
- 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
请检查此代码并告诉我它是否对您有所帮助。