いろいろ備忘録日記

主に .NET とか Go とか Flutter とか Python絡みのメモを公開しています。

Pythonメモ-54 (py.test と pytest) (pytest, command, since version 3.0)

概要

普段お世話になっている pytest さんなのですが、ネットで情報みると

py.testってなっているものと pytestってなっているものが

あります。

バージョンが異なるのかなって思って見てみても

$ py.test --version
This is pytest version 3.3.0, imported from /Users/xxxx/anaconda3/envs/pudb/lib/python3.6/site-packages/pytest.py
setuptools registered plugins:
  pytest-pudb-0.5 at /Users/xxxx/anaconda3/envs/pudb/lib/python3.6/site-packages/pytest_pudb.py
  hypothesis-3.38.5 at /Users/xxxx/anaconda3/envs/pudb/lib/python3.6/site-packages/hypothesis/extra/pytestplugin.py
$ pytest --version
This is pytest version 3.3.0, imported from /Users/xxxx/anaconda3/envs/pudb/lib/python3.6/site-packages/pytest.py
setuptools registered plugins:
  pytest-pudb-0.5 at /Users/xxxx/anaconda3/envs/pudb/lib/python3.6/site-packages/pytest_pudb.py
  hypothesis-3.38.5 at /Users/xxxx/anaconda3/envs/pudb/lib/python3.6/site-packages/hypothesis/extra/pytestplugin.py

全く同じに見える。

場所が異なるのかなって思って見てみても

$ which pytest
/Users/xxxx/anaconda3/envs/pudb/bin/pytest
$ which py.test
/Users/xxxx/anaconda3/envs/pudb/bin/py.test

全く同じに見える。

ファイルの情報は?

$ ls -l (which pytest) (which py.test)
-rwxrwxr-x  1 xxxx  staff  241  1  9 04:04 /Users/xxxx/anaconda3/envs/pudb/bin/py.test
-rwxrwxr-x  1 xxxx  staff  241  1  9 04:04 /Users/xxxx/anaconda3/envs/pudb/bin/pytest

全く同じ。何が違うねん?ってなってました。

py.testは古いコマンドだった

ネットで情報探すと以下の情報が見つかりました。

stackoverflow.com

上記からさらにリンクたどると以下のissueに到達。

github.com

つまり、こういう事とのこと。

  • version 3.0 から pytest コマンドがメインコマンドになりました。

  • py.test コマンドは、非推奨となっているので、その内なくなるかも。

  • もともと、pytestは pyモジュールの一部だったので、py.test ってなってた。

ということで、pytestコマンドの方を使うのが現在の正解みたいです。


過去の記事については、以下のページからご参照下さい。

サンプルコードは、以下の場所で公開しています。