pytestのpluginどこまで使うか
はじめに
pytestのpluginをどこまで使うかを考えるのがめんどくさくなったりした。
個人的にはそれぞれのタイミングで必要になったらはじめて手に取るべきで、あまり最初から導入するようなpluginは思いつかなかった。必要になったタイミングで追加して手に馴染むものがあれば使っていけば良いのでは位のスタンス。
一方で、デフォルトに乗るというか、大衆に従うというか、無難に使うということを考えた時に、どこまでのpytest pluginを利用するべきなんだろうかも気になったりした。
方法
例えば、以下の様に考えてみると、何が無難なパッケージかを判断できるかもしれない。
pip search pytest
で検索できるpackageの一覧を取り出す- それぞれのpackageをdownloads数順に良い感じに並べる
- (追加で基準となりそうな馴染み深いパッケージも加えておく)
- ソートした後に、新たに追加された馴染み深いpackageを上回っているものが無難なパッケージ
ということで
pip search pytest
で検索できるpackageの一覧を取り出す
$ pip search pytest | grep -v '^ ' | wc 100 864 7127
100件くらい。どうにかなりそう。すごくびっくりするほど多いわけではない。
$ pip search pytest | grep -v '^ ' | head -n 3 pytest (4.5.0) - pytest: simple powerful testing with Python pytest-httpserver (0.3.0) - pytest-httpserver is a httpserver for pytest pytest-bdd (3.1.0) - BDD for pytest
それぞれのpackageをdownloads数順に良い感じに並べる
pypistatsでとりあえずてきとうに集める。あんまりたくさんAPIを呼ぶのはマナーが悪いけれど、100件くらいならまぁ良いでしょうということで(pypistatsについては以前書いた)。
$ pypistats recent pytest -f json {"data": {"last_day": 456962, "last_month": 8510196, "last_week": 2674612}, "package": "pytest", "type": "recent_downloads"}
全部集める。
$ pip search pytest | grep -v '^ ' | cut -d " " -f 1 | xargs -I{} pypistats recent {} -f json | tee stats.json
(追加で基準となりそうな馴染み深いパッケージも加えておく)
なじみのある名前のパッケージも追加しておく
$ pypistats recent flake8 -f json >> stats.json $ pypistats recent pandas -f json >> stats.json $ pypistats recent flask -f json >> stats.json $ pypistats recent arrow -f json >> stats.json $ pypistats recent twine -f json >> stats.json $ pypistats recent marshmallow -f json >> stats.json $ pypistats recent aiohttp -f json >> stats.json
ソートした後に、新たに追加された馴染み深いpackageを上回っているものが無難なパッケージ
てきとうにsortしてあげる。そしてjsonからmarkdownにしてあげる。
$ jqfpy --slurp 'data = [{"package": d["package"], **d["data"]} for d in get()]; sorted(data, ke y=lambda d: d["last_month"] + 4 * d["last_week"], reverse=True)' stats.json | dictknife cat -i json -o md | tee sorted.md
結論はこんな感じになった。
- pytest-covくらいで良いのでは
もしかしたら以下のパッケージくらいは検討の余地があるかもしれない。
- pytest-django (djangoのappを使っている場合は)
- pytest-sugar
- pytest-asyncio
- pytest-repeat
- pytest-aiohttp (aiohttpを使っている場合には)
それぞれのダウンロード数(直近のもの)
package | last_day | last_month | last_week |
---|---|---|---|
pandas | 426686 | 9451489 | 3018160 |
pytest | 456962 | 8510196 | 2674612 |
aiohttp | 618024 | 4751605 | 3223056 |
flask | 376027 | 7474443 | 2322232 |
pytest-cov | 150069 | 2783678 | 961471 |
flake8 | 145502 | 3023160 | 868458 |
arrow | 64539 | 1316746 | 368395 |
marshmallow | 45679 | 901455 | 257934 |
pytest-django | 25164 | 478969 | 137959 |
twine | 16439 | 353383 | 102052 |
pytest-sugar | 7772 | 171525 | 48550 |
pytest-asyncio | 7939 | 149570 | 44024 |
pytest-pep8 | 3331 | 79564 | 20891 |
pytest-repeat | 2994 | 63269 | 17581 |
pytest-aiohttp | 3107 | 56605 | 16705 |
pytest-selenium | 3083 | 56677 | 15271 |
allure-pytest | 2198 | 39679 | 12461 |
pytest-factoryboy | 1688 | 32099 | 9805 |
pytest-bdd | 1374 | 31177 | 8241 |
pytest-cover | 787 | 13670 | 4348 |
pytest-sanic | 896 | 13242 | 4454 |
pytest-doctestplus | 508 | 12967 | 3817 |
pytest-salt | 537 | 11821 | 3504 |
pytest-splinter | 553 | 8464 | 2800 |
pytest-describe | 490 | 5964 | 2388 |
pytest-faker | 394 | 7393 | 1922 |
pytest-csv | 212 | 6137 | 1600 |
pytest-pycodestyle | 374 | 5050 | 1774 |
pytest-pudb | 324 | 5126 | 1697 |
pytest-codestyle | 244 | 4268 | 1350 |
pytest-trio | 269 | 4342 | 1269 |
pytest-runfailed | 171 | 3944 | 1070 |
pytest-xpara | 165 | 3724 | 1008 |
behave-pytest | 212 | 3189 | 893 |
pytest-regtest | 127 | 3104 | 826 |
pytest-libfaketime | 70 | 2125 | 626 |
pytest-ethereum | 20 | 1873 | 675 |
pytest-invenio | 153 | 1778 | 653 |
pytest-localstack | 44 | 1966 | 410 |
pytest-mongodb | 102 | 1668 | 433 |
pytest-testdox | 31 | 1676 | 391 |
pytest-firefox | 98 | 1487 | 419 |
pytest-grpc | 104 | 1007 | 413 |
pybuilder-pytest | 19 | 1034 | 342 |
pytest-docstyle | 41 | 1152 | 278 |
pytest-testconfig | 68 | 796 | 357 |
pytest-warnings | 36 | 952 | 228 |
pytest-fxa | 47 | 783 | 243 |
pytest-pydocstyle | 57 | 724 | 251 |
pytest-httpserver | 54 | 618 | 232 |
hypothesis-pytest | 42 | 709 | 170 |
pytest-sqlalchemy | 40 | 497 | 201 |
pytest-expecter | 16 | 613 | 166 |
pygments-pytest | 11 | 657 | 143 |
pytest-httpretty | 23 | 399 | 131 |
pytest-fixtures | 18 | 403 | 108 |
pytest-smartcov | 47 | 342 | 80 |
pytest-monkeyplus | 6 | 198 | 100 |
pytest-dynamodb | 8 | 281 | 77 |
pytest-falcon | 17 | 292 | 73 |
pytest-bandit | 8 | 290 | 50 |
pytest-monkeytype | 3 | 240 | 55 |
pytest-toolbox | 1 | 245 | 45 |
pytest-pdb | 5 | 223 | 41 |
pytest-annotate | 1 | 290 | 13 |
pytest-slack | 2 | 186 | 37 |
pytest-diff | 2 | 209 | 31 |
pytest-curio | 0 | 163 | 35 |
pytest-neo | 3 | 213 | 19 |
pytest-rage | 10 | 127 | 38 |
pytest-reqs | 1 | 190 | 21 |
pytest-excel | 4 | 131 | 33 |
pytest-trepan | 7 | 150 | 26 |
pytest-sourceorder | 18 | 129 | 31 |
pytest-jest | 3 | 102 | 34 |
pytest-bench | 1 | 151 | 21 |
pytest-fauxfactory | 0 | 107 | 31 |
pytest-reana | 0 | 202 | 6 |
pytest-flake8dir | 0 | 122 | 21 |
pytest-race | 5 | 92 | 27 |
pytest-docs | 2 | 124 | 11 |
pytest-airflow | 0 | 115 | 12 |
pytest-ponyorm | 1 | 113 | 12 |
pytest-ngsfixtures | 0 | 145 | 4 |
pytest-pyq | 2 | 77 | 20 |
pytest-apistellar | 0 | 112 | 11 |
pytest-orchestration | 1 | 102 | 13 |
pytest-statsd | 3 | 97 | 11 |
pytest-assertutil | 0 | 97 | 8 |
pytest-datatest | 2 | 66 | 10 |
pytest-diamond | 2 | 45 | 11 |
pytest-tesults | 0 | 56 | 8 |
pytest-rt | 0 | 47 | 9 |
pytest-pytestrail | 0 | 50 | 8 |
pytest-zafira | 0 | 52 | 6 |
pytest-scenario | 1 | 49 | 6 |
pytest-cram | 0 | 42 | 5 |
pytest-ok | 1 | 36 | 6 |
geoffrey-pytest | 0 | 36 | 6 |
pytest-pact | 0 | 33 | 6 |
pytest-growl | 1 | 34 | 5 |
pytest-rethinkdb | 0 | 35 | 4 |
pytest-cricri | 0 | 31 | 4 |
pytest-nginx | 0 | 29 | 3 |
pytest-symbols | 0 | 23 | 4 |
pytest-redmine | 0 | 21 | 3 |
memo
以下をinstallする必要があるかも
$ pip install pypistats jqfpy dictknife