[py-svn] r8059 - in py/dist/py: documentation test/testing test/testing/test/data
hpk at codespeak.net
hpk at codespeak.net
Mon Jan 3 19:19:43 CET 2005
Author: hpk
Date: Mon Jan 3 19:19:33 2005
New Revision: 8059
Removed:
py/dist/py/test/testing/test/data/Collector.py
Modified:
py/dist/py/documentation/test.txt
py/dist/py/test/testing/test_collect.py
Log:
get rid of the old "Collector at module-level" hack
because we have generative tests now. Fix documentation.
Modified: py/dist/py/documentation/test.txt
==============================================================================
--- py/dist/py/documentation/test.txt (original)
+++ py/dist/py/documentation/test.txt Mon Jan 3 19:19:33 2005
@@ -88,6 +88,9 @@
can be customized at each level. (see `collection process`_
for some implementation details).
+
+.. _`generative tests`:
+
generative tests: yielding more tests
-------------------------------------
@@ -423,21 +426,27 @@
If you have a module where you want to take responsibility for
collecting your own test Items and possibly even for executing
-a test then you can provide your own ``Collector`` at module
-level. The default ModuleCollector looks for the name
-``Collector`` in the modules namespace and turns over
-reponsibility by invoking it with the "module-path".
-
-The module path is a ``py.path.py()`` instance and carries
-information needed to traverse to to the module. In general,
-a pypath allows to address a python object on the filesystem.
-*Addressability of test Items* is a major concern because we
-want to memorize failing tests across py.test invocations. A
-``pypath`` has two parts, a filesystem path and a dotted path
-leading to the python object. Another benefits, apart from
-from addressability, is that invoking setup/teardown operations
-can simply be implemented by walking the path to the python
-object.
+a test then you can provide `generative tests`_ that yield
+callables and possibly arguments as a tuple. This should
+serve most immediate purposes.
+
+Another extension possibility goes deeper into the machinery
+and allows you to specify a custom test ``Item`` class which
+is responsible for setting up and executing an underlying
+test. You can integrate your custom ``py.test.Item`` subclass
+by putting an ``Item`` binding on a test class. Or you can
+take over larger parts of the collection process by tweaking the
+``conftest.py`` file. The collection process constantly looks at
+such configuration files to determine appropriate collectors at
+``Directory``, ``Module`` or ``Class`` level.
+
+When providing ``Items`` you have to deal with ``py.path.extpy()``
+paths. In general, an extpy-path allows to address a python object
+on a filesystem. *Addressability of test Items* is a major concern
+because we want to memorize failing tests across py.test invocations.
+The extpy-path is also walked in order to setup/teardown resources.
+A ``py.path.extpy()`` has two parts, a filesystem path pointing to
+a module and a dotted path leading to the python object.
Customizing execution of Items
------------------------------
Deleted: /py/dist/py/test/testing/test/data/Collector.py
==============================================================================
--- /py/dist/py/test/testing/test/data/Collector.py Mon Jan 3 19:19:33 2005
+++ (empty file)
@@ -1,21 +0,0 @@
-from __future__ import generators
-import py
-
-class Collector(py.test.collect.PyCollector):
- def collect_function(self, pypath):
- if pypath.check(func=1, basestarts='myprefix_'):
- yield self.Item(pypath, pypath.basename)
-
-def myprefix_1(arg):
- assert arg == 'myprefix_1'
-def myprefix_2(arg):
- assert arg == 'myprefix_2'
-def myprefix_3(arg):
- assert arg == 'myprefix_3'
-
-def test_this_should_not_be_called():
- assert 1 != 0, "should not be collected"
-
-class TestA:
- def test_this_should_not_be_called(self):
- assert 1 != 0, "should not be collected"
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 Mon Jan 3 19:19:33 2005
@@ -45,21 +45,22 @@
l = list(collect.Class(extpy))
assert len(l) == 0
-class TestCustomCollector:
- def test_custom_collect(self):
- l = list(collect.Module(datadir.join('Collector.py')))
- for item in l:
- assert isinstance(item, py.test.Item)
- assert len(l) == 3
- #for x in l2:
- # assert isinstance(x, Unit)
- # x.execute()
-
class Testsomeclass:
disabled = True
def test_something():
raise ValueError
+
+class TestWithCustomItem:
+ class Item(py.test.Item):
+ flag = []
+ def execute(self, target, *args):
+ self.flag.append(42)
+ target(*args)
+
+ def test_hello(self):
+ assert self.Item.flag == [42]
+
l = []
def test_1():
l.append(1)
More information about the pytest-commit
mailing list