Skip to content

Commit

Permalink
Merge pull request #860 from nicoddemus/warn-plugins-as-str-main
Browse files Browse the repository at this point in the history
Make passing plugins as str objects a more obvious failure
  • Loading branch information
nicoddemus committed Jul 24, 2015
2 parents 4f1ae8c + 35bbcc3 commit 91e8e59
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,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

0 comments on commit 91e8e59

Please sign in to comment.