From 819e0ead44dd3c6990c9376820bd0223c44b73d1 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Thu, 3 Mar 2016 18:26:01 -0300 Subject: [PATCH] Mention that pytest_addoption may be used from conftest files fix #1427 --- _pytest/hookspec.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/_pytest/hookspec.py b/_pytest/hookspec.py index 224b7971c..4c79d1d5e 100644 --- a/_pytest/hookspec.py +++ b/_pytest/hookspec.py @@ -28,17 +28,14 @@ def pytest_plugin_registered(plugin, manager): @hookspec(historic=True) def pytest_addoption(parser): - """register argparse-style options and ini-style config values. + """register argparse-style options and ini-style config values, + called once at the beginning of a test run. - .. warning:: + .. note:: - This function must be implemented in a :ref:`plugin ` - and is called once at the beginning of a test run. - - Implementing this hook from ``conftest.py`` files is **strongly** - discouraged because ``conftest.py`` files are lazily loaded and - may give strange *unknown option* errors depending on the directory - ``py.test`` is invoked from. + This function should be implemented only in plugins or ``conftest.py`` + files situated at the tests root directory due to how py.test + :ref:`discovers plugins during startup `. :arg parser: To add command line options, call :py:func:`parser.addoption(...) <_pytest.config.Parser.addoption>`.