113 lines
4.8 KiB
Plaintext
113 lines
4.8 KiB
Plaintext
|
|
.. _`non-python tests`:
|
|
|
|
Python 以外のテストを扱う
|
|
=========================
|
|
|
|
..
|
|
Working with non-python tests
|
|
====================================================
|
|
|
|
.. _`yaml plugin`:
|
|
|
|
Yaml ファイルでテストを指定する基本的なサンプル
|
|
-----------------------------------------------
|
|
|
|
..
|
|
A basic example for specifying tests in Yaml files
|
|
--------------------------------------------------------------
|
|
|
|
.. _`pytest-yamlwsgi`: http://bitbucket.org/aafshar/pytest-yamlwsgi/src/tip/pytest_yamlwsgi.py
|
|
.. _`PyYAML`: http://pypi.python.org/pypi/PyYAML/
|
|
|
|
..
|
|
Here is an example ``conftest.py`` (extracted from Ali Afshnars special purpose `pytest-yamlwsgi`_ plugin). This ``conftest.py`` will collect ``test*.yml`` files and will execute the yaml-formatted content as custom tests:
|
|
|
|
``conftest.py`` (Ali Afshnars の特殊用途の `pytest-yamlwsgi`_ プラグインから引用) のサンプルを紹介します。この ``conftest.py`` は ``test*.yml`` ファイルを探してきて、yaml フォーマットのコンテンツをカスタムテストとして実行します:
|
|
|
|
.. include:: nonpython/conftest.py
|
|
:literal:
|
|
|
|
..
|
|
You can create a simple example file:
|
|
|
|
簡単なサンプルファイルを作成します:
|
|
|
|
.. include:: nonpython/test_simple.yml
|
|
:literal:
|
|
|
|
..
|
|
and if you installed `PyYAML`_ or a compatible YAML-parser you can
|
|
now execute the test specification::
|
|
|
|
`PyYAML`_ か、互換性のある YAML パーサーをインストール済みなら、そのテスト仕様を実行できます::
|
|
|
|
nonpython $ py.test test_simple.yml
|
|
=========================== test session starts ============================
|
|
platform linux2 -- Python 2.7.1 -- pytest-2.2.4
|
|
collecting ... collected 2 items
|
|
|
|
test_simple.yml .F
|
|
|
|
================================= FAILURES =================================
|
|
______________________________ usecase: hello ______________________________
|
|
usecase execution failed
|
|
spec failed: 'some': 'other'
|
|
no further details known at this point.
|
|
==================== 1 failed, 1 passed in 0.06 seconds ====================
|
|
|
|
..
|
|
You get one dot for the passing ``sub1: sub1`` check and one failure.
|
|
Obviously in the above ``conftest.py`` you'll want to implement a more
|
|
interesting interpretation of the yaml-values. You can easily write
|
|
your own domain specific testing language this way.
|
|
|
|
``sub1: sub1`` は成功してドットを1つ表示し、もう1つは失敗します。上述した ``conftest.py`` は言うまでもなく単純なので、もっとおもしろい yaml 値を解釈するサンプルを実装したくなるでしょう。このように独自のドメイン固有テスト言語を簡単に記述できます。
|
|
|
|
.. note::
|
|
|
|
..
|
|
``repr_failure(excinfo)`` is called for representing test failures.
|
|
If you create custom collection nodes you can return an error
|
|
representation string of your choice. It
|
|
will be reported as a (red) string.
|
|
|
|
``repr_failure(excinfo)`` はテストの失敗を表現するために呼ばれます。カスタムコレクションのノードを作成する場合、好きなエラーを表現する文字列を返せます。それは (赤い) 文字列で表示されます。
|
|
|
|
..
|
|
``reportinfo()`` is used for representing the test location and is also
|
|
consulted when reporting in ``verbose`` mode::
|
|
|
|
``reportinfo()`` はテストの位置を表現したり、 ``verbose`` モードではレポート時にも使われます::
|
|
|
|
nonpython $ py.test -v
|
|
=========================== test session starts ============================
|
|
platform linux2 -- Python 2.7.1 -- pytest-2.2.4 -- /home/hpk/venv/0/bin/python
|
|
collecting ... collected 2 items
|
|
|
|
test_simple.yml:1: usecase: ok PASSED
|
|
test_simple.yml:1: usecase: hello FAILED
|
|
|
|
================================= FAILURES =================================
|
|
______________________________ usecase: hello ______________________________
|
|
usecase execution failed
|
|
spec failed: 'some': 'other'
|
|
no further details known at this point.
|
|
==================== 1 failed, 1 passed in 0.06 seconds ====================
|
|
|
|
..
|
|
While developing your custom test collection and execution it's also
|
|
interesting to just look at the collection tree::
|
|
|
|
カスタムテストコレクションや実行処理の開発中、そのコレクションツリーをちょっと見るのもおもしろいです::
|
|
|
|
nonpython $ py.test --collectonly
|
|
=========================== test session starts ============================
|
|
platform linux2 -- Python 2.7.1 -- pytest-2.2.4
|
|
collecting ... collected 2 items
|
|
<YamlFile 'test_simple.yml'>
|
|
<YamlItem 'ok'>
|
|
<YamlItem 'hello'>
|
|
|
|
============================= in 0.07 seconds =============================
|