簡體   English   中英

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

文件夾結構 SAMFOLDER -.aws-sam --build --build.toml -samconfig.toml -template -lambda --requirements --Test_app
樣品測試:

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.```    

首先,您應該確保您的測試用例從給定數據中以test_ ,在我看來,您沒有正確設置測試。 例如,這是您的應用程序的正確結構。

  • 我的應用程序/
    • 運行.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

檢查此代碼並告訴我它是否對您有幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM