@@ -127,10 +127,39 @@ It's a prime example of `dependency injection`_ where fixture
127127functions take the role of the *injector * and test functions are the
128128*consumers * of fixture objects.
129129
130+ .. _`conftest.py` :
131+ .. _`conftest` :
132+
133+ ``conftest.py ``: sharing fixture functions
134+ ------------------------------------------
135+
136+ If during implementing your tests you realize that you
137+ want to use a fixture function from multiple test files you can move it
138+ to a ``conftest.py `` file.
139+ You don't need to import the fixture you want to use in a test, it
140+ automatically gets discovered by pytest. The discovery of
141+ fixture functions starts at test classes, then test modules, then
142+ ``conftest.py `` files and finally builtin and third party plugins.
143+
144+ You can also use the ``conftest.py `` file to implement
145+ :ref: `local per-directory plugins <conftest.py plugins >`.
146+
147+ Sharing test data
148+ -----------------
149+
150+ If you want to make test data from files available to your tests, a good way
151+ to do this is by loading these data in a fixture for use by your tests.
152+ This makes use of the automatic caching mechanisms of pytest.
153+
154+ Another good approach is by adding the data files in the ``tests `` folder.
155+ There are also community plugins available to help managing this aspect of
156+ testing, e.g. `pytest-datadir <https://github.com/gabrielcnr/pytest-datadir >`__
157+ and `pytest-datafiles <https://pypi.python.org/pypi/pytest-datafiles >`__.
158+
130159.. _smtpshared :
131160
132- Scope: Sharing a fixture across tests in a class, module or session
133- -------------------------------------------------------------------
161+ Scope: sharing a fixture instance across tests in a class, module or session
162+ ----------------------------------------------------------------------------
134163
135164.. regendoc:wipe
136165
@@ -878,17 +907,6 @@ All test methods in this TestClass will use the transaction fixture while
878907other test classes or functions in the module will not use it unless
879908they also add a ``transact `` reference.
880909
881-
882- Shifting (visibility of) fixture functions
883- ----------------------------------------------------
884-
885- If during implementing your tests you realize that you
886- want to use a fixture function from multiple test files you can move it
887- to a :ref: `conftest.py <conftest.py >` file or even separately installable
888- :ref: `plugins <plugins >` without changing test code. The discovery of
889- fixtures functions starts at test classes, then test modules, then
890- ``conftest.py `` files and finally builtin and third party plugins.
891-
892910Overriding fixtures on various levels
893911-------------------------------------
894912
0 commit comments