LoginSignup
3
2

More than 5 years have passed since last update.

pytest + webtest + pyramid

Posted at

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

3
2
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
3
2