[py-svn] r6991 - in py/dist: doc example/test py/test/report/text

hpk at codespeak.net hpk at codespeak.net
Mon Oct 18 00:57:50 CEST 2004


Author: hpk
Date: Mon Oct 18 00:57:49 2004
New Revision: 6991

Modified:
   py/dist/doc/test.txt
   py/dist/example/test/failure_demo.py
   py/dist/py/test/report/text/summary.py
Log:
made the reporter display traceback information 
more nicely (i think) 

some fixes/extensions to the test document. 


Modified: py/dist/doc/test.txt
==============================================================================
--- py/dist/doc/test.txt	(original)
+++ py/dist/doc/test.txt	Mon Oct 18 00:57:49 2004
@@ -26,11 +26,13 @@
 The existence of a standalone ``py.test`` tool allows 
 to write tests without any boilerplate::
 
+    # content of test_sample.py 
     def test_answer():
         assert 42 == 43 
 
-this would be the complete content of a ``test_sample.py``
-test script and you can execute the tests by invoking::
+In contrast to ``unitest.py`` limitations you 
+can have test functions as well as test methods.   
+You can execute the test by invoking::
 
     py.test test_sample.py 
 
@@ -38,30 +40,30 @@
 on your system. 
 
 
-Basic features for writing tests
-================================
+Features of ``py.test`` 
+=======================
 
 assert with the ``assert`` statement
 ------------------------------------
 
-writing assertions is very simple and this
-is one of py.tests most noticeable features: 
-
-    You can simply use the ``assert`` statement. 
-
-For example you can write: 
-
-     assert hasattr(x, 'something') 
-
-and in case this fails the ``test reporter`` will provide 
-you with a very helpful analysis and a clean traceback. 
-
-Please note that in order to display helpful analysis 
-of a failing ``assert`` expression some magic takes 
-place behind the scenes.  For now, you only need to 
-know that if something looks strange or you suspect
-a bug in that behind-the-scenes-magic you may turn 
-of the magic by providing the ``--nomagic`` option. 
+Writing assertions is very simple and this is one of py.tests
+most noticeable features, as you can use the ``assert``
+statement with arbitrary expressions.  For example you can 
+write the following in your tests:: 
+
+     assert hasattr(x, 'attribute') 
+
+to state that your object has a certain ``attribute``
+and in case this assertion fails the test ``reporter`` 
+will provide you with a very helpful analysis and a 
+clean traceback. 
+
+Note that in order to display helpful analysis of a failing
+``assert`` statement some magic takes place behind the
+scenes.  For now, you only need to know that if something
+looks strange or you suspect a bug in that
+*behind-the-scenes-magic* you may turn of the magic by 
+providing the ``--nomagic`` option. 
 
 how to write assertions about execptions 
 ----------------------------------------
@@ -92,6 +94,15 @@
 you will find that they execute in exactly the same order
 within each file. 
 
+useful tracebacks, recursion detection 
+--------------------------------------
+
+You will at some point notice that a lot of care is taken
+to present nice tracebacks.  Tracebacks usually start 
+with your failing test function and they will abort early
+in case of recursion with a statement stating the
+recursion. 
+
 Managing test state across test modules, classes and methods 
 ------------------------------------------------------------ 
 

Modified: py/dist/example/test/failure_demo.py
==============================================================================
--- py/dist/example/test/failure_demo.py	(original)
+++ py/dist/example/test/failure_demo.py	Mon Oct 18 00:57:49 2004
@@ -27,27 +27,27 @@
             return 43
         somefunc(f(), g())
 
-    def test_z1_unpack_error():
+    def test_z1_unpack_error(self):
         l = []
         a,b  = l
 
-    def test_z2_type_error():
+    def test_z2_type_error(self):
         l = 3
         a,b  = l
 
-    def test_startswith():
+    def test_startswith(self):
         s = "123"
         g = "456"
         assert s.startswith(g) 
 
-    def test_startswith_nested():
+    def test_startswith_nested(self):
         def f():   
             return "123"
         def g():   
             return "456"
         assert f().startswith(g())
 
-    def test_global_func():
+    def test_global_func(self):
         assert isinstance(globf(42), float)
 
     def test_instance(self):

Modified: py/dist/py/test/report/text/summary.py
==============================================================================
--- py/dist/py/test/report/text/summary.py	(original)
+++ py/dist/py/test/report/text/summary.py	Mon Oct 18 00:57:49 2004
@@ -98,10 +98,10 @@
             pass
         else:
             if out.strip():
-                self.out.sep("- ", "recorded pyout")
+                self.out.sep("- ", "recorded stdout")
                 self.out.line(out.strip())
             if err.strip():
-                self.out.sep("- ", "recorded pyerr")
+                self.out.sep("- ", "recorded stderr")
                 self.out.line(err.strip())
         #self.out.line()
 
@@ -109,7 +109,7 @@
         cls = res.excinfo[0]
         if issubclass(cls, run.ExceptionFailure):
             if not res.innerexcinfo:
-                self.out.line(">>> %s <<<  DID NOT RAISE" % (res.expr,))
+                self.out.line("%s <<<  DID NOT RAISE" % (res.expr,))
                 self.out.line("expected: %r" % (res.expected,))
             else:
                 self.out.write("%r raised wrong Exception, " % (res.expr,))
@@ -186,8 +186,14 @@
         return old
 
     def repr_traceback(self, unit, tb, tbindex=-1):
-        self.out.line(">>> %s" % unit.pypath) 
-        self.repr_traceback_raw(unit.pypath.fspath, tb, tbindex)
+        t_file, t_lineno = unit.pypath.getfilelineno() 
+        self.out.line("%s, line %d" % (unit.pypath, t_lineno) )
+        fspath = unit.pypath.fspath 
+        self.repr_traceback_raw(fspath, tb, tbindex)
+        #t_file, t_lineno = unit.pypath.getfilelineno() 
+        #if t_file != filename or lineno != t_lineno:
+        #self.out.line("%s, line %d" % (unit.pypath, t_lineno) )
+        self.out.sep('-')
 
     def repr_traceback_raw(self, fspath, tb, tbindex=-1):
         if fspath and not self.option.fulltrace:
@@ -200,6 +206,7 @@
 
         recursioncache = {}
         for tb in tbentries:
+            self.out.sep('-')
             filename = tb.tb_frame.f_code.co_filename 
             lineno = tb.tb_lineno
             name = tb.tb_frame.f_code.co_name
@@ -207,8 +214,8 @@
             #showfn = filename.split(os.sep)
             #if len(showfn) > 5:
             #    showfn = os.sep.join(['...'] + showfn[-5:])
-            self.out.line(">>> %r, line %d" %(showfn, lineno)) # , name))
             self.repr_source(tb.tb_frame, lineno)
+            self.out.line("> %s, line %d" %(showfn, lineno)) # , name))
             if self.option.showlocals:
                 self.out.sep('- ', 'locals')
                 for name, value in tb.tb_frame.f_locals.items():
@@ -216,7 +223,6 @@
             key = (filename, lineno)
             if key not in recursioncache:
                 recursioncache.setdefault(key, []).append(tb.tb_frame.f_locals)
-                self.out.sep('-')
             else:
                 loc = tb.tb_frame.f_locals 
                 for x in recursioncache[key]:
@@ -224,7 +230,7 @@
                         self.out.line("Recursion detected (same locals & position)")
                         break
                 else:
-                    self.out.sep('-')
+                    #self.out.sep('-')
                     continue
                 break
 



More information about the pytest-commit mailing list