Skip to content

Commit

Permalink
Fix issue where pytest_plugins as string were marking wrong modules f…
Browse files Browse the repository at this point in the history
…or rewrite

Fix pytest-dev#1888
  • Loading branch information
nicoddemus committed Aug 31, 2016
1 parent 82218e4 commit 72bd1c7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions _pytest/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,8 @@ def consider_env(self):

def consider_module(self, mod):
plugins = getattr(mod, 'pytest_plugins', [])
if isinstance(plugins, str):
plugins = [plugins]
self.rewrite_hook.mark_rewrite(*plugins)
self._import_plugin_specs(plugins)

Expand Down
23 changes: 23 additions & 0 deletions testing/test_assertion.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,29 @@ def test_foo(check_first):
assert 0
result.stdout.fnmatch_lines([expected])

@pytest.mark.parametrize('mode', ['str', 'list'])
def test_pytest_plugins_rewrite_module_names(self, testdir, mode):
"""Test that pluginmanager correct marks pytest_plugins variables
for assertion rewriting if they are defined as plain strings or
list of strings (#1888).
"""
plugins = '"ham"' if mode == 'str' else '["ham"]'
contents = {
'conftest.py': """
pytest_plugins = {plugins}
""".format(plugins=plugins),
'ham.py': """
import pytest
""",
'test_foo.py': """
def test_foo(pytestconfig):
assert 'ham' in pytestconfig.pluginmanager.rewrite_hook._must_rewrite
""",
}
testdir.makepyfile(**contents)
result = testdir.runpytest_subprocess('--assert=rewrite')
assert result.ret == 0

@pytest.mark.parametrize('mode', ['plain', 'rewrite'])
def test_installed_plugin_rewrite(self, testdir, mode):
# Make sure the hook is installed early enough so that plugins
Expand Down

0 comments on commit 72bd1c7

Please sign in to comment.