[py-svn] r16121 - in py/dist/py/test: . testing
jan at codespeak.net
jan at codespeak.net
Thu Aug 18 00:10:27 CEST 2005
Author: jan
Date: Thu Aug 18 00:10:25 2005
New Revision: 16121
Modified:
py/dist/py/test/collect.py
py/dist/py/test/item.py
py/dist/py/test/testing/test_collect.py
Log:
issue16
ensure right order of generative tests
Modified: py/dist/py/test/collect.py
==============================================================================
--- py/dist/py/test/collect.py (original)
+++ py/dist/py/test/collect.py Thu Aug 18 00:10:25 2005
@@ -361,7 +361,7 @@
if not callable(call):
raise TypeError("yielded test %r not callable" %(call,))
name = "[%d]" % i
- d[name] = self.Function(name, self, args, obj=call)
+ d[name] = self.Function(name, self, args, obj=call, sort_value = i)
return d
def getcallargs(self, obj):
Modified: py/dist/py/test/item.py
==============================================================================
--- py/dist/py/test/item.py (original)
+++ py/dist/py/test/item.py Thu Aug 18 00:10:25 2005
@@ -40,20 +40,22 @@
def finishcapture(self):
if hasattr(self, '_capture'):
capture = self._capture
- del self._capture
+ del self._capture
self.captured_out, self.captured_err = capture.reset()
+
class Function(Item):
""" a Function Item is responsible for setting up
and executing a Python callable test object.
"""
state = SetupState()
- def __init__(self, name, parent, args=(), obj=_dummy):
+ def __init__(self, name, parent, args=(), obj=_dummy, sort_value = None):
super(Function, self).__init__(name, parent)
self.args = args
if obj is not _dummy:
self._obj = obj
-
+ self.sort_value = sort_value
+
def __repr__(self):
return "<%s %r>" %(self.__class__.__name__, self.name)
@@ -62,7 +64,9 @@
return code.path, code.firstlineno
def getsortvalue(self):
- return self.getpathlineno()
+ if self.sort_value is None:
+ return self.getpathlineno()
+ return self.sort_value
def run(self):
self.state.prepare(self)
Modified: py/dist/py/test/testing/test_collect.py
==============================================================================
--- py/dist/py/test/testing/test_collect.py (original)
+++ py/dist/py/test/testing/test_collect.py Thu Aug 18 00:10:25 2005
@@ -187,3 +187,46 @@
assert len(l) == 2
finally:
old.chdir()
+
+
+def test_order_of_execution_generator_same_codeline():
+ test_list = []
+ expected_list = range(6)
+
+ def list_append(item):
+ test_list.append(item)
+
+ def assert_order_of_execution():
+ print 'expected order', expected_list
+ print 'but got ', test_list
+ assert test_list == expected_list
+
+ for i in expected_list:
+ yield list_append, i
+ yield assert_order_of_execution
+
+
+
+def test_order_of_execution_generator_different_codeline():
+ test_list = []
+ expected_list = range(3)
+
+ def list_append_2():
+ test_list.append(2)
+
+ def list_append_1():
+ test_list.append(1)
+
+ def list_append_0():
+ test_list.append(0)
+
+ def assert_order_of_execution():
+ print 'expected order', expected_list
+ print 'but got ', test_list
+ assert test_list == expected_list
+
+ yield list_append_0
+ yield list_append_1
+ yield list_append_2
+ yield assert_order_of_execution
+
More information about the pytest-commit
mailing list