@@ -236,20 +236,31 @@ import ``helper.py`` normally. The contents of
236
236
Requiring/Loading plugins in a test module or conftest file
237
237
-----------------------------------------------------------
238
238
239
- You can require plugins in a test module or a conftest file like this: :
239
+ You can require plugins in a test module or a `` conftest.py `` file like this:
240
240
241
- pytest_plugins = "name1", "name2",
241
+ .. code-block :: python
242
+
243
+ pytest_plugins = [" name1" , " name2" ]
242
244
243
245
When the test module or conftest plugin is loaded the specified plugins
244
- will be loaded as well. You can also use dotted path like this::
246
+ will be loaded as well. Any module can be blessed as a plugin, including internal
247
+ application modules:
248
+
249
+ .. code-block :: python
245
250
246
251
pytest_plugins = " myapp.testsupport.myplugin"
247
252
248
- which will import the specified module as a ``pytest `` plugin.
253
+ ``pytest_plugins `` variables are processed recursively, so note that in the example above
254
+ if ``myapp.testsupport.myplugin `` also declares ``pytest_plugins ``, the contents
255
+ of the variable will also be loaded as plugins, and so on.
256
+
257
+ This mechanism makes it easy to share textures within applications or even
258
+ external applications without the need to create external plugins using
259
+ the ``setuptools ``'s entry point technique.
249
260
250
- Plugins imported like this will automatically be marked to require
251
- assertion rewriting using the :func: `pytest.register_assert_rewrite `
252
- mechanism. However for this to have any effect the module must not be
261
+ Plugins imported by `` pytest_plugins `` will also automatically be marked
262
+ for assertion rewriting (see :func: `pytest.register_assert_rewrite `).
263
+ However for this to have any effect the module must not be
253
264
imported already; if it was already imported at the time the
254
265
``pytest_plugins `` statement is processed, a warning will result and
255
266
assertions inside the plugin will not be re-written. To fix this you
0 commit comments