@@ -127,10 +127,39 @@ It's a prime example of `dependency injection`_ where fixture
127
127
functions take the role of the *injector * and test functions are the
128
128
*consumers * of fixture objects.
129
129
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
+
130
159
.. _smtpshared :
131
160
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
+ ----------------------------------------------------------------------------
134
163
135
164
.. regendoc:wipe
136
165
@@ -878,17 +907,6 @@ All test methods in this TestClass will use the transaction fixture while
878
907
other test classes or functions in the module will not use it unless
879
908
they also add a ``transact `` reference.
880
909
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
-
892
910
Overriding fixtures on various levels
893
911
-------------------------------------
894
912
0 commit comments