LoginSignup
6
6

More than 5 years have passed since last update.

pytestが勝手に生成するキャッシュ用ディレクトリを無効にする

Last updated at Posted at 2018-06-28

AWS Lambda 上で pytest を動かす というのをやったときに、pytestが勝手に作成するキャッシュ用ディレクトリのせいでLambdaから怒られて動かなかったので調べたときのメモ。

検証環境

  • AWS Lambda: python3.6 runtime
  • MacOS Sierra 10.12.6: python 3.6
  • Ubuntu 16.04 LTS: python 3.5

pytestが勝手に生成するキャッシュ用ディレクトリを無効にする

Lambda 上で pytest を動作させてみると、こんなエラーが発生。

OSError: [Errno 30] Read-only file system: '/var/task/.pytest_cache'

見ての通り Read-onlyの領域に書き込みにいって怒られている。
調べてみると、pytestは勝手に .pytest_cache というdirectoryを作成するらしく、ここに書き込み・参照を行うと。
cacheのpathを tmp/.pytest_cache とかに変更できればよいのですが、そういったoptionは見つからず。
※ tmp配下はlambda上で読み書きが許可されている

更に調べると、下記のリポジトリ issue がHit。
Github/pytest: pytest2.8 invariantly writes to working directory + fails on readonly filesystem
cache を pytest 実行時に使用させないOptionを pytest.ini に記載すれば、cache機能が使われなくなるようだ。

pytest.ini

pytest.ini
[pytest]
addopts = -p no:cacheprovider

このOption付きで Lambda 上で再度 pytest を実行すると成功。念の為 Local環境 (Mac + Ubuntu) でも当設定をした状態でpytestを実施してみたが、 .pytest_cache directoryは作成されなかった。

参考リンク

6
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6