ツール
pytest
Python で最も広く使われているテストフレームワーク。素の assert とフィクスチャで書けるが、テストの収集規則・conftest.py の配置・インポートパスの解決で詰まりやすい。
問題一覧(5)
pytest「async def functions are not natively supported」の原因と直し方
pytest の async def functions are not natively supported は、async def のテストを動かすプラグインが無いと出る。pytest-asyncio を入れ、テストに印を付けるか asyncio_mode = auto にすれば直る。
更新: 2026-11-07、タグ: asyncio、pytest-asyncio、async-def
pytest で「fixture 'xxx' not found」が出てフィクスチャを使えない
fixture 'xxx' not found は、フィクスチャを上位の conftest.py へ移すか、プラグインを入れれば直る。綴り違いも含め、pytest --fixtures の一覧で切り分けられる。
更新: 2026-10-24、タグ: fixture、conftest、pytest-mock
pytest で「import file mismatch」が出て同じ名前のテストファイルを収集できない
import file mismatch は、テストファイル名を一意にするか、__init__.py を置くか、importlib モードにすれば直る。同名のテストファイルが同じモジュール名で衝突すると出る。
更新: 2026-10-28、タグ: import、collection、import-mode
pytest でテストから自作モジュールを import できない(ModuleNotFoundError)
pytest はプロジェクトのルートではなく、テストファイル側のディレクトリを sys.path に足す。src レイアウトなら設定の pythonpath か編集可能インストール、フラットな構成なら python -m pytest か tests/__init__.py で解決する。
更新: 2026-11-09、タグ: import、modulenotfounderror、sys-path
pytest でテストが見つからず実行できない(collected 0 items / no tests ran)
pytest は命名規則に合うファイル・関数・クラスだけを集める。test_*.py か *_test.py のファイル、test で始まる関数、__init__ の無い Test で始まるクラスに揃え、pytest --collect-only で何が集まるかを確かめる。
更新: 2026-10-25、タグ: collection、naming、python_files