CircleCI의 PythonOrbs를 사용하세요.

CircleCI의 PythonOrbs(을)를 사용하면, CI로 테스트를(를) 수행하고 작업을 할 수 있습니다.

작업리포지트리




유타고토 / python_ci_testing






python_ci_testing





View on GitHub



やったこと



Pipfileを用意



今回は mypypytestpycodestyle を使います.

[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]

[dev-packages]
mypy = "*"
pytest = "*"
pycodestyle = "*"

[requires]
python_version = "3.8"

산프루를 사용하다



# app.py
def greeting(name: str) -> str:
    return 'hello ' + name


print(greeting('name'))

테스트파일을용도



# test_app.py
import app


def test_greeting():
    assert app.greeting('name') == 'hello name'

ファイルを用意したら pushします.

CircleCI의 準備



https://app.circleci.com

CircleCI에 악세스하고, 左menu-のProjects에서 리포지트리를 択하고 셋트할 수 있습니다.

(브라우자상으로 .circleci/config.yml を編集できるの便利)



데포르트데셋트されている

orbs:
  python: circleci/[email protected]

はorbのバージョンは結構古いので,Orbsのページを見て最新バージョンに書き換えます(2021/03/31時点では 1.3.3 が最new)

https://circleci.com/developer/orbs/orb/circleci/python

steps内にある load-cache , save-cache は今は1.3.3では使えない(라이브러리의 Instorl 時にAutomotive でキッシュしてくれる)ので削除します.

ライブラリのインストールは、今回作った三プルではpipenvを使うのでネストさせた要素の pkg-manager:pipenv を書きます(CI環境なので引数に --dev ゑをま付)

사용 예には、Testを実行させるために python/test を使うような記述がありますが、stepsでは使わずにjobsに直接指定します.

できあがった.circleci/config.yml が以下입니다.

# .circleci/config.yml
version: 2.1

orbs:
  python: circleci/[email protected]

jobs:
  build-and-test:
    executor: python/default
    steps:
      - checkout
      - python/install-packages:
          args: --dev
          pkg-manager: pipenv
      - run:
          name: mypy
          command: pipenv run mypy .
      - run:
          name: pycodestyle
          command: pipenv run pycodestyle .

workflows:
  main:
    jobs:
      - build-and-test
      - python/test:
          args: --dev
          test-tool: pytest
          pkg-manager: pipenv

Testを実行する部分で python/install-packages とほぼ同じ記述になってしまうのはどうにかしたい部分はあります..





Circleci 프로젝트 설정 #2







YutaGoto
에 게시됨





View on GitHub

좋은 웹페이지 즐겨찾기