[Checkins] SVN: zope.pytest/trunk/doc/grok_samples.rst starting grok py.test howto

Christian Klinger cklinger at novareto.de
Wed Jan 19 04:45:04 EST 2011


Log message for revision 119691:
  starting grok py.test howto

Changed:
  A   zope.pytest/trunk/doc/grok_samples.rst

-=-
Added: zope.pytest/trunk/doc/grok_samples.rst
===================================================================
--- zope.pytest/trunk/doc/grok_samples.rst	                        (rev 0)
+++ zope.pytest/trunk/doc/grok_samples.rst	2011-01-19 09:45:04 UTC (rev 119691)
@@ -0,0 +1,92 @@
+py.test examples for Grok
+=========================
+
+In typical Zpe/Grok development we know three kind of tests:
+
+  - unit-tests
+  - integration-tests
+  - funktional-tests
+
+With the help of py.test we can create and run all of these tests in 
+an easy way for Grok. In this tutorial we will demonstrate the
+usage of zope.pytest with this three kind of tests.
+
+
+Buildout
+--------
+
+Let's start with extending the default generated buildout.cfg by 
+grokproject to use zope.pytest.
+
+To find all relevant packages of pytest we have to add 
+
+    http://pypi.testrun.org/simple/py/
+
+to the find_links.
+
+Then we can add a new part called 'pytest'. Don't forget to add it 
+to the global parts too!
+
+Here is the pytest section:
+
+    [pytest]
+    recipe = z3c.recipe.scripts
+    eggs =
+      example 
+      pytest
+    arguments = ['src/example'] + sys.argv[1:]
+
+Please notice the 'example' is the name of the package which is
+generated by grokproject.
+
+After running bin/buildout we should have a new executable called
+bin/py.test which search for tests in the directory src/example.
+
+
+unit-tests
+----------
+
+To run unit-tests with pytest we have to create a file with the
+prefix 'test_'. Ok so let's create a file test_unit.py with the
+following content.
+
+.. code-block:: python
+
+    class TestClass:
+
+        def test_one(self):
+            x = "this"
+            assert 'h' in x
+
+        def test_two(self):
+            x = "servus"
+            assert x == "hello"
+
+
+Now we can run this test with bin/py.test we should get one failing
+test:
+
+.. code-block:: bash
+    ==================================== FAILURES =====================================
+    _______________________________ TestClass.test_two ________________________________
+
+    self = <pytt.tests.test_unit.TestClass instance at 0x1042d0950>
+
+        def test_two(self):
+            x = "servus"
+    >       assert x == "hello"
+    E       assert 'servus' == 'hello'
+    E         - servus
+    E         + hello
+
+    src/pytt/tests/test_unit.py:9: AssertionError
+    ======================= 1 failed, 3 passed in 1.14 seconds ========================
+
+
+integration-tests
+-----------------
+
+
+
+functional-tests
+----------------



More information about the checkins mailing list