remove outdated IMPL.txt and move up-to-date doc bits to FixtureMapper class.

This commit is contained in:
holger krekel 2012-10-16 16:27:51 +02:00
parent cc2337af3a
commit 2855a2f6cb
2 changed files with 32 additions and 40 deletions

View File

@ -1,40 +0,0 @@
internal fixture mechanics
----------------------------
fixture mechanics are contained in the python.py plugin.
pytest fixtures are stored and managed from the FixtureManager (fm) class.
Upon collection fm.parsefactories() is called multiple times to parse
fixture function definitions into FixtureDef objects.
During collection of test functions, metafunc needs to grow a "fixturenames"
list so that pytest_generate_tests() hooks can check it. These fixturenames
are a closure of all known fixtures to be used for this function:
- ini-defined usefixtures
- autouse-marked fixtures along the collection chain up from the function
- usefixtures markers at module/class/function level
- test function funcargs
The latter list (without the closure) is also called "_initialfixtures"
and will be used during the test setup phase.
Upon the test-setup phases initialfixtures are instantiated which
will subsequently create the full fixture closure (as was computed in
metafunc.fixturenames during collection). As fixture functions
can invoke request.getfuncargvalue() the actual closure may be even
bigger.
object model
---------------------
As part of the metafunc-protocol parents of Function nodes get a
ParentFixtures() object, containing helping/caching for
for a function. .getfixtureinfo(func) returns a FixtureInfo with these
attributes:
- names_initial: list of initial fixture names (see above)
- names_closure: closure of all fixture names
- name2fixturedefs: for creating the value

View File

@ -327,6 +327,38 @@ class PyCollector(PyobjMixin, pytest.Collector):
keywords={callspec.id:True}) keywords={callspec.id:True})
class FixtureMapper: class FixtureMapper:
"""
pytest fixtures definitions and information is stored and managed
from this class.
During collection fm.parsefactories() is called multiple times to parse
fixture function definitions into FixtureDef objects and internal
data structures.
During collection of test functions, metafunc-mechanics instantiate
a FuncFixtureInfo object which is cached in a FixtureMapper instance
which itself lives on the parent collector. This FuncFixtureInfo object
is later retrieved by Function nodes which themselves offer a fixturenames
attribute.
The FuncFixtureInfo object holds information about fixtures and FixtureDefs
relevant for a particular function. An initial list of fixtures is
assembled like this:
- ini-defined usefixtures
- autouse-marked fixtures along the collection chain up from the function
- usefixtures markers at module/class/function level
- test function funcargs
Subsequently the funcfixtureinfo.fixturenames attribute is computed
as the closure of the fixtures needed to setup the initial fixtures,
i. e. fixtures needed by fixture functions themselves are appended
to the fixturenames list.
Upon the test-setup phases all fixturenames are instantiated, retrieved
by a lookup on a FixtureMapper().
"""
def __init__(self, node, funcargs=True): def __init__(self, node, funcargs=True):
self.node = node self.node = node
self.fm = node.session._fixturemanager self.fm = node.session._fixturemanager