.. _`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 =============================