summaryrefslogtreecommitdiff
path: root/testing/test_pluginmanager.py
diff options
context:
space:
mode:
authorJoshua Storck <joshua.storck@twosigma.com>2019-10-30 14:18:13 -0400
committerJoshua Storck <joshua.storck@twosigma.com>2019-10-30 14:18:13 -0400
commit7a96d94fd4f98f725ce04f7ac45de041b521b86d (patch)
treef8a5f3528cddf3581457eee591b937d17f3fe27d /testing/test_pluginmanager.py
parentcefe6bfec38f8f9e200b2e233a840cf1de2bf3b4 (diff)
downloadpytest-7a96d94fd4f98f725ce04f7ac45de041b521b86d.tar.gz
Making it possible to access the pluginmanager in the pytest_addoption hook
Diffstat (limited to 'testing/test_pluginmanager.py')
-rw-r--r--testing/test_pluginmanager.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/testing/test_pluginmanager.py b/testing/test_pluginmanager.py
index 97f220ca5..836b458c6 100644
--- a/testing/test_pluginmanager.py
+++ b/testing/test_pluginmanager.py
@@ -135,6 +135,36 @@ class TestPytestPluginInteractions:
ihook_b = session.gethookproxy(testdir.tmpdir.join("tests"))
assert ihook_a is not ihook_b
+ def test_hook_with_addoption(self, testdir):
+ """Test that hooks can be used in a call to pytest_addoption"""
+ testdir.makepyfile(
+ newhooks="""
+ import pytest
+ @pytest.hookspec(firstresult=True)
+ def pytest_default_value():
+ pass
+ """
+ )
+ testdir.makepyfile(
+ myplugin="""
+ import newhooks
+ def pytest_addhooks(pluginmanager):
+ pluginmanager.add_hookspecs(newhooks)
+ def pytest_addoption(parser, pluginmanager):
+ default_value = pluginmanager.hook.pytest_default_value()
+ parser.addoption("--config", help="Config, defaults to %(default)s", default=default_value)
+ """
+ )
+ testdir.makeconftest(
+ """
+ pytest_plugins=("myplugin",)
+ def pytest_default_value():
+ return "default_value"
+ """
+ )
+ res = testdir.runpytest("--help")
+ res.stdout.fnmatch_lines(["*--config=CONFIG*default_value*"])
+
def test_default_markers(testdir):
result = testdir.runpytest("--markers")