From ccf7584fac39fa2bec58e7d5d9c114dc9eb060f2 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Thu, 27 Aug 2015 19:14:56 -0300 Subject: [PATCH] Add warning about implementing pytest_addoption from conftest files --- _pytest/hookspec.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/_pytest/hookspec.py b/_pytest/hookspec.py index c75f563f4..0bdc60638 100644 --- a/_pytest/hookspec.py +++ b/_pytest/hookspec.py @@ -30,8 +30,15 @@ def pytest_plugin_registered(plugin, manager): def pytest_addoption(parser): """register argparse-style options and ini-style config values. - This function must be implemented in a :ref:`plugin ` and is - called once at the beginning of a test run. + .. warning:: + + 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. :arg parser: To add command line options, call :py:func:`parser.addoption(...) <_pytest.config.Parser.addoption>`.