RyosukeDTomita / pytest-with-docker

Create pytest environment with docker.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

pytest with docker

un license unit-test

INDEX


ABOUT

  • pytestのpyファイル名はtest_application.pyのように命名する。
  • pytestのpyファイルはtests/test_mainappのようにする。
  • 各ディレクトリに__init__.pyを配置する。
  • pytestの詳細はこちらを参照。
.
├── app
│   └── mainapp
│       ├── application.py
│       ├── __init__.py
│       └── __pycache__
│           ├── application.cpython-38.pyc
│           └── __init__.cpython-38.pyc
├── docker-compose.yml
├── Dockerfile
├── README.md
└── tests
    ├── __init__.py
    ├── __pycache__
    │   └── __init__.cpython-38.pyc
    └── test_mainapp
        ├── __init__.py
        ├── __pycache__
        │   ├── __init__.cpython-38.pyc
        │   └── test_application.cpython-38-PYTEST.pyc
        └── test_application.py

LICENSE


UN LICENSE


ENVIRONMENT

  • ubuntu22.04(docker)

PREPARING

  1. install docker
  2. download this repository.

HOW TO USE

  • pythonのバージョンはDockerfileで指定しているので適宜書き換える。
docker buildx bake
docker compose run pytest-env "cd /pytest-with-docker && /pyenv/versions/3.9.6/bin/pytest"

Note

ローカルでpytestを実行するなら毎回docker runで無駄にコンテナを立ち上げずに起動したコンテナに対してexecでpytest実行したほうがいいかも。 コンテナはタスクが終わると自動で終了してしまうので,DockerfileのCMDでtail -f /dev/null等してコンテナを実行したままの状態にする。 現状コメントアウトされているので外す(これをやるとgithub actionsで実行しているpytestが動かなくなるので注意)。

docker compose up -d
docker compose exec pytest-env /bin/bash -c "cd /pytest-with-docker && /pyenv/versions/3.9.6/bin/pytest"
  • github actionsでも実行可能。

Warning

CMD等でコマンドを実行するようにしてdocker compose up等するとテストの結果にかかわらず,コマンドが実行できたらステータスコードが0になるのでbuildとrunに分けている。

About

Create pytest environment with docker.

License:The Unlicense


Languages

Language:Python 63.2%Language:Dockerfile 36.8%