PPP3: Circle CI (続き)
機能はunittest
を生で使ったけれども今日はpytest
で
jUnit形式で結果を出力してCircleCIにレポートしてもらう
$ pytest --junit-xml=test_result.xml
...
------ generated xml file: /home/takahiro/study/PPP3-mac/circleci/test_result.xml ------
...
pytestを実行して結果を保存するようconfig.ymlを修正
...
steps:
- checkout
- run: |
python3.6 -m venv venv
source ./venv/bin/activate
pip install pytest
pytest test_calculations.py --junit-xml=test-results/pytest.xml
- store_test_results:
path: test-results
config.ymlが正しいことをローカルで確認する方法はないのかな?
commitしてpushしたら間違ってました、ってなるのやだし
#!/bin/sh -eo pipefail
# Unable to parse YAML
# while scanning a simple key
# in 'string', line 9, column 9:
# python3.6 -m venv venv
# ^
# could not find expected ':'
# in 'string', line 10, column 9:
# source ./venv/bin/activate
# ^
#
# -------
# Warning: This configuration was auto-generated to show you the message above.
# Don't rerun this job. Rerunning will have no effect.
false
Exited with code 1
ほらな
pushしちゃったらgit reset
とかしないよな
ところで何が悪いんだこれ
サンプルと同じように見えるけど・・・
もしかしてインデントが足りない?
こうなの?
...
- run: |
python3.6 -m venv venv
source ./venv/bin/activate
pip install pytest
pytest test_calculations.py --junit-xml=test-results/pytest.xml
- store_test_results:
path: test-results
通った
Test Summary
Your job ran 2 tests in unknown with 0 failures
Slowest test: test_calculations.CalculationsTest test_divide_contain_zero (took 0.00 seconds).
あとちょっと試す
CircleCIはビルド実行ごとに実行環境を新規作成するため仮想環境を使用しなくても構いませんが、今回は開発環境と併せて仮想環境を作成します。
仮想環境って作ったほうがいいのかなあ
なしでやってみるねと
...
- run: |
pip install pytest
pytest test_calculations.py --junit-xml=test-results/pytest.xml
...
えーFAILなの
ERROR: Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/usr/local/lib/python3.6/site-packages/packaging'
Consider using the `--user` option or check the permissions.
なるほどね
sudo
ってできるんだろうか
ダメかな
--user
つけるほうがいいか
でもちょっと興味あるからsudoしてみる
...
- run: |
sudo pip install pytest
...
おっと通った
sudoできるようになってるんだ
コンテナだからそんなあやしいことはできないってことかな
なお仮想環境作ったときは24秒、今回は16秒で完了している
でもばらつきありそうな気もするしたまたまかも
--user
もやっとく
...
- run: |
pip install --user pytest
...
push
Collecting pytest
...
Installing collected packages: wcwidth, packaging, more-itertools, zipp, importlib-metadata, pluggy, py, atomicwrites, pytest
WARNING: The scripts py.test and pytest are installed in '/home/circleci/.local/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed atomicwrites-1.3.0 importlib-metadata-0.18 more-itertools-7.0.0 packaging-19.0 pluggy-0.12.0 py-1.8.0 pytest-4.6.3 wcwidth-0.1.7 zipp-0.5.1
/bin/bash: line 1: pytest: command not found
Exited with code 127
ぐぬぬ
sudoの方がよかったのか
pushしちゃってたらどうするんだっけ?
git revert
してもう一度pushするくらい?