Reputation: 37
I have a github repository that has a file Test_app.py
. I am running a pytest on the file in github actions and keep getting the error message: E botocore.exceptions.NoRegionError: You must specify a region.
I then specify the region in my file as: dynamodb = boto3.resource('dynamodb', region_name= 'eu-west-2')
. And get the following error when I execute a 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.
This is my lambda code:
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")
and this is the workflow for the 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
folder structure
SAMFOLDER
-.aws-sam
--build
--build.toml
-samconfig.toml
-template
-lambda
--requirements
--Test_app
sample Test:
Requirement already satisfied: pytest in c:\hostedtoolcache\windows\python\3.8.6\x64\lib\site-packages (6.2.0)
Requirement already satisfied: toml in c:\hostedtoolcache\windows\python\3.8.6\x64\lib\site-packages (from pytest) (0.10.2)
Requirement already satisfied: attrs>=19.2.0 in c:\hostedtoolcache\windows\python\3.8.6\x64\lib\site-packages (from pytest) (20.3.0)
Requirement already satisfied: colorama in c:\hostedtoolcache\windows\python\3.8.6\x64\lib\site-packages (from pytest) (0.4.4)
Requirement already satisfied: iniconfig in c:\hostedtoolcache\windows\python\3.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\3.8.6\x64\lib\site-packages (from pytest) (0.13.1)
Requirement already satisfied: packaging in c:\hostedtoolcache\windows\python\3.8.6\x64\lib\site-packages (from pytest) (20.8)
Requirement already satisfied: py>=1.8.2 in c:\hostedtoolcache\windows\python\3.8.6\x64\lib\site-packages (from pytest) (1.10.0)
Requirement already satisfied: atomicwrites>=1.0 in c:\hostedtoolcache\windows\python\3.8.6\x64\lib\site-packages (from pytest) (1.4.0)
Requirement already satisfied: pyparsing>=2.0.2 in c:\hostedtoolcache\windows\python\3.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.```
Upvotes: 0
Views: 3617
Reputation: 625
First of all, you should make sure that your test cases start with test_
from the given data it seems to me that you didn't properly set up tests. For example, this is the correct structure for your app.
Inside test_function_1.py
you should have:
# Just for the sake of the example
def test_func_case_1():
assert True
def test_func_case_2():
assert 1 == 1
Check this code and tell me if it helped you.
Upvotes: 2