前置き
個人的なメモです。
Github ActionsでDjangoのテストをpytestで実行しています。
先日下記のようにactions/setup-python@v1
でエラーが発生しました。
main.yml
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v1
with:
python-version: 3.8.2
- run: python -m pip install --upgrade pip
- run: pip install pipenv
- run: pipenv install -d
- run: pipenv run pytest -n auto --cov
エラーの内容はこちらです。
console.log
## [error]Version 3.8.2 with arch x64 not found
Available versions:
2.7.18 (x64)
3.5.9 (x64)
3.6.10 (x64)
3.7.7 (x64)
3.8.3 (x64)
本題
actions/setup-python@v2
では3.8.2
が使用できそうだったので、
とりあえずバージョンを変更して実行してみました。
その結果、pytestのテストでエラーが発生しました。
エラーの内容はこんな感じです。
console.log
==================================== ERRORS ====================================
_ ERROR collecting 6e684b56-631b-4b6c-932f-7229ff10dace/lib/python3.8/ctypes/test/test_anon.py _
import file mismatch:
imported module 'ctypes.test.test_anon' has this __file__ attribute:
/opt/hostedtoolcache/Python/3.8.2/x64/lib/python3.8/ctypes/test/test_anon.py
which is not the same as the test file we want to collect:
/home/runner/work/xxxx/xxxx/6e684b56-631b-4b6c-932f-7229ff10dace/lib/python3.8/ctypes/test/test_anon.py
HINT: remove __pycache__ / .pyc files and/or use a unique basename for your test file modules
(省略)
原因
調べた所、ワークディレクトリにライブラリがダウンロードされており、
そのディレクトリがテスト対象に含めているのが原因でした。
解決方法
とりあえず、pytestの設定(pytest.ini)でuuidっぽいディレクトリはテスト対象外にして解決しました。
pytest.ini
[pytest]
norecursedirs = *-*-*-*-*
もっと良い方法もありそうです。。