Commits

Ronny Pfannschmidt  committed e5b72d7

start initial proof of concept subtest/report writeup

  • Participants
  • Parent commits ceafafc
  • Branches subtest-doc

Comments (0)

Files changed (1)

File doc/en/subtest.txt

+Subreports and Subtests
+==========================
+
+Subtests and subrepots provide a facility to divide a single test into
+multiple distinguishable sections.
+
+This allows to test elements of an iteration separately or
+partition different parts of an acceptance tests.
+
+
+Subtests
+---------
+
+SubTests are intended to do distinct separate tests within a surrounding test.
+A failure of such an test is not considered a failure of the surrounding test.
+
+Given those properties there are 2 major use-cases for subtests
+
+1. examination of iteration::
+
+    # content of test_iteration.py
+    items = dict(zip(range(10), range(10)))
+    items[4] = 5
+    def test_reported_data():
+        for key, value in items:
+            with pytest.subtest(key, value, pytest.mark.xfail(key==4))
+                assert key == value
+
+
+::
+    $ py.test
+
+
+2. non fatal assertions in acceptance tests
+
+    # content of test module
+    import pytest
+
+    def test_user_can_register():
+        user = register_new_user(...)
+        with subtest('fresh cant log in'):
+            with pytest.raises(Http403):
+                login(user.name, user.oh_so_unsecure_password_store)
+
+        user.activate()
+
+        with subtest('active can log in'):
+            login(user.name, user.oh_so_unsecure_password_store)
+
+
+Subreports
+----------
+
+Subreports are intended to partition a test into manageable sections.
+This eases acceptance-testing, since only the relevant reports have to be shown.
+
+::
+    # content of test_acceptance.py
+
+    import pytest
+
+    @pytest.fixture
+    def application(request):
+        with subreport('create app')
+            app = make_app()
+        with subreport('configure app'):
+            app.configure(requst.config)
+        return app
+
+
+    def test_user_registration(app):
+        with subreport('registration'):
+            app.register('test:test')
+        with subreport('activation'):
+            app.activate('test')
+        with subreport('first_login'):
+            ...
+
+
+::
+    $ py.test
+
+
+
+
+
+
+
+
+
+
+