pyramidで開発したアプリを、WebTestで機能テストする方法はここに書いてあります。
このテストを、pytestで実行しようとしてもうまくいきません。元のドキュメントに書いてある通りです。pytest may not include your tests.
また、pytestのドキュメント読んでいると、どうもunittest
を使うとうまくいかないような気持ちになって来ます。例えば、せっかくのparametrized testも、テストクラスをunittestのサブクラスにしていると動作しません。
そんなわけで、pyramidアプリをpytest+webtestでテストする構成はこんな感じにしました。
conftest.py
import pytest
def pytest_report_header(config):
return "sample: functional tests"
@pytest.fixture
def app():
""" prepare test target app """
from app import main
main_app = main({})
from webtest import TestApp
return TestApp(main_app)
tests.py
import pytest
@pytest.mark.usefixtures("app")
def test_not_found(app):
res = app.get('/', status=404)
以下省略
ようやく、pytestでテストが書けそうな気分になって来ました。parametrized testは最高に便利だと思います。
参考
- http://akirachiku.com/2014/04/14/django-pytest-webtest.html