Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make passing plugins as str objects a more obvious failure #860

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
- fix issue856: consider --color parameter in all outputs (for example
--fixtures). Thanks Barney Gale for the report and Bruno Oliveira for the PR.

- fix issue855: passing str objects as `plugins` argument to pytest.main
is now interpreted as a module name to be imported and registered as a
plugin, instead of silently having no effect.
Thanks xmo-odoo for the report and Bruno Oliveira for the PR.

- fix issue744: fix for ast.Call changes in Python 3.5+. Thanks
Guido van Rossum, Matthias Bussonnier, Stefan Zimmermann and
Thomas Kluyver.
Expand Down
5 changes: 4 additions & 1 deletion _pytest/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ def _prepareconfig(args=None, plugins=None):
try:
if plugins:
for plugin in plugins:
pluginmanager.register(plugin)
if isinstance(plugin, py.builtin._basestring):
pluginmanager.consider_pluginarg(plugin)
else:
pluginmanager.register(plugin)
return pluginmanager.hook.pytest_cmdline_parse(
pluginmanager=pluginmanager, args=args)
except Exception:
Expand Down
16 changes: 16 additions & 0 deletions testing/acceptance_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sys
import py, pytest

class TestGeneralUsage:
Expand Down Expand Up @@ -370,6 +371,21 @@ def test_foo(invalid_fixture):
"*fixture 'invalid_fixture' not found",
])

def test_plugins_given_as_strings(self, tmpdir, monkeypatch):
"""test that str values passed to main() as `plugins` arg
are interpreted as module names to be imported and registered.
#855.
"""
with pytest.raises(ImportError) as excinfo:
pytest.main([str(tmpdir)], plugins=['invalid.module'])
assert 'invalid' in str(excinfo.value)

p = tmpdir.join('test_test_plugins_given_as_strings.py')
p.write('def test_foo(): pass')
mod = py.std.types.ModuleType("myplugin")
monkeypatch.setitem(sys.modules, 'myplugin', mod)
assert pytest.main(args=[str(tmpdir)], plugins=['myplugin']) == 0


class TestInvocationVariants:
def test_earlyinit(self, testdir):
Expand Down