test_ok1/doc/en/example/nonpython.rst

101 lines
3.7 KiB
ReStructuredText
Raw Normal View History

.. _`non-python tests`:
Working with non-python tests
====================================================
2010-11-06 06:37:25 +08:00
.. _`yaml plugin`:
A basic example for specifying tests in Yaml files
--------------------------------------------------------------
.. _`pytest-yamlwsgi`: http://bitbucket.org/aafshar/pytest-yamlwsgi/src/tip/pytest_yamlwsgi.py
.. _`PyYAML`: https://pypi.org/project/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:
.. 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
2018-11-24 13:41:22 +08:00
now execute the test specification:
.. code-block:: pytest
nonpython $ pytest test_simple.yml
2019-01-06 03:19:40 +08:00
=========================== test session starts ============================
2018-11-24 04:09:57 +08:00
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y
2019-01-31 00:25:38 +08:00
cachedir: $PYTHON_PREFIX/.pytest_cache
2019-04-15 22:24:17 +08:00
rootdir: $REGENDOC_TMPDIR/nonpython
collected 2 items
2019-01-06 03:19:40 +08:00
test_simple.yml F. [100%]
2019-01-06 03:19:40 +08:00
================================= FAILURES =================================
______________________________ usecase: hello ______________________________
usecase execution failed
spec failed: 'some': 'other'
no further details known at this point.
2019-01-06 03:19:40 +08:00
==================== 1 failed, 1 passed in 0.12 seconds ====================
.. regendoc:wipe
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
2010-11-06 06:37:25 +08:00
interesting interpretation of the yaml-values. You can easily write
your own domain specific testing language this way.
.. note::
``repr_failure(excinfo)`` is called for representing test failures.
If you create custom collection nodes you can return an error
2010-11-06 06:37:25 +08:00
representation string of your choice. It
will be reported as a (red) string.
``reportinfo()`` is used for representing the test location and is also
2018-11-24 13:41:22 +08:00
consulted when reporting in ``verbose`` mode:
.. code-block:: pytest
nonpython $ pytest -v
2019-01-06 03:19:40 +08:00
=========================== test session starts ============================
2019-01-31 00:25:38 +08:00
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_PREFIX/bin/python
cachedir: $PYTHON_PREFIX/.pytest_cache
2019-04-15 22:24:17 +08:00
rootdir: $REGENDOC_TMPDIR/nonpython
collecting ... collected 2 items
2019-01-06 03:19:40 +08:00
test_simple.yml::hello FAILED [ 50%]
test_simple.yml::ok PASSED [100%]
2019-01-06 03:19:40 +08:00
================================= FAILURES =================================
______________________________ usecase: hello ______________________________
usecase execution failed
spec failed: 'some': 'other'
no further details known at this point.
2019-01-06 03:19:40 +08:00
==================== 1 failed, 1 passed in 0.12 seconds ====================
.. regendoc:wipe
While developing your custom test collection and execution it's also
2018-11-24 13:41:22 +08:00
interesting to just look at the collection tree:
.. code-block:: pytest
nonpython $ pytest --collect-only
2019-01-06 03:19:40 +08:00
=========================== test session starts ============================
2018-11-24 04:09:57 +08:00
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y
2019-01-31 00:25:38 +08:00
cachedir: $PYTHON_PREFIX/.pytest_cache
2019-04-15 22:24:17 +08:00
rootdir: $REGENDOC_TMPDIR/nonpython
collected 2 items
2019-04-15 22:24:17 +08:00
<Package $REGENDOC_TMPDIR/nonpython>
2019-01-05 23:21:49 +08:00
<YamlFile test_simple.yml>
<YamlItem hello>
<YamlItem ok>
2019-01-06 03:19:40 +08:00
======================= no tests ran in 0.12 seconds =======================