webmaster-kazu.com

テクノロジー・データ分析・実践ログ・その他

Pythonのテストフレームワーク「pytest」をインストールする

カテゴリ: Python【初歩から現場実務的なもの】

Pythonのテストが行えるフレームワークライブラリである「pytest」のインストールについて解説しています。(Windows10)

pytestモジュールを使用することで、小さなテストを簡単に書くことができます。また、アプリケーションやライブラリの複雑な機能テストをサポートするように拡張することもできます。

■Python

今回のPythonのバージョンは、「3.8.5」を使用しています。(Windows10)(pythonランチャーでの確認)

■pytestをインストールする

pytestをインストールを行いますが、今回はpipを経由してインストールを行うので、まずWindowsのコマンドプロンプトを起動します。

pip install pytest

起動後、上記のコマンドを入力し、Enterキーを押します。

なお、今回は、pythonランチャーを使用しており、Python Version 3.8.5にインストールを行うために、pipを使う場合にはコマンドでの切り替えを行います。

py -3.8 -m pip install pytest

切り替えるために、上記のコマンドを入力し、Enterキーを押します。

Collecting pytest

Downloading pytest-6.2.3-py3-none-any.whl (280 kB)

|████████████████████████████████| 280 kB 1.3 MB/s

Collecting pluggy<1.0.0a1,>=0.12

Downloading pluggy-0.13.1-py2.py3-none-any.whl (18 kB)

Collecting atomicwrites>=1.0; sys_platform == "win32"

Downloading atomicwrites-1.4.0-py2.py3-none-any.whl (6.8 kB)

Collecting iniconfig

Downloading iniconfig-1.1.1-py2.py3-none-any.whl (5.0 kB)

Requirement already satisfied: attrs>=19.2.0 in c:\pg\python38\lib\site-packages (from pytest) (20.3.0)

Collecting toml

Downloading toml-0.10.2-py2.py3-none-any.whl (16 kB)

Requirement already satisfied: colorama; sys_platform == "win32" in c:\pg\python38\lib\site-packages (from pytest) (0.4.4)

Collecting py>=1.8.2

Downloading py-1.10.0-py2.py3-none-any.whl (97 kB)

|████████████████████████████████| 97 kB 1.3 MB/s

Requirement already satisfied: packaging in c:\pg\python38\lib\site-packages (from pytest) (20.7)

Requirement already satisfied: pyparsing>=2.0.2 in c:\pg\python38\lib\site-packages (from packaging->pytest) (2.4.7)

Installing collected packages: pluggy, atomicwrites, iniconfig, toml, py, pytest

Successfully installed atomicwrites-1.4.0 iniconfig-1.1.1 pluggy-0.13.1 py-1.10.0 pytest-6.2.3 toml-0.10.2

Enterキーを押すと、インストールが開始され、上記のように「Successfully installed」と表示されます。これが表示されれば、pytestが正常にインストールされたことになります。

なお、「Requirement already satisfied」と表示されると、すでにインストールは行われています。