Skip to content

Commit 678dfaa

Browse files
authored
Merge pull request #4728 from nicoddemus/usage-error-module
Do not raise UsageError when "pytest_plugins" is a module
2 parents c780d1f + 19c93d1 commit 678dfaa

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

changelog/3899.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Do not raise ``UsageError`` when an imported package has a ``pytest_plugins.py`` child module.

src/_pytest/config/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -559,8 +559,8 @@ def _get_plugin_specs_as_list(specs):
559559
which case it is returned as a list. Specs can also be `None` in which case an
560560
empty list is returned.
561561
"""
562-
if specs is not None:
563-
if isinstance(specs, str):
562+
if specs is not None and not isinstance(specs, types.ModuleType):
563+
if isinstance(specs, six.string_types):
564564
specs = specs.split(",") if specs else []
565565
if not isinstance(specs, (list, tuple)):
566566
raise UsageError(

testing/acceptance_test.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -969,6 +969,20 @@ def test(): pass
969969
assert r.ret == 0
970970

971971

972+
def test_pytest_plugins_as_module(testdir):
973+
"""Do not raise an error if pytest_plugins attribute is a module (#3899)"""
974+
testdir.makepyfile(
975+
**{
976+
"__init__.py": "",
977+
"pytest_plugins.py": "",
978+
"conftest.py": "from . import pytest_plugins",
979+
"test_foo.py": "def test(): pass",
980+
}
981+
)
982+
result = testdir.runpytest()
983+
result.stdout.fnmatch_lines("* 1 passed in *")
984+
985+
972986
def test_deferred_hook_checking(testdir):
973987
"""
974988
Check hooks as late as possible (#1821).

0 commit comments

Comments
 (0)