From feb4b2249a605328410e181a1790b5ebad1ad9ff Mon Sep 17 00:00:00 2001 From: holger krekel Date: Thu, 23 Apr 2015 13:15:34 +0200 Subject: [PATCH] remove some redundancy when parsing import spec --HG-- branch : plugin_no_pytest --- _pytest/config.py | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/_pytest/config.py b/_pytest/config.py index eb575e8b5..7948a7c39 100644 --- a/_pytest/config.py +++ b/_pytest/config.py @@ -232,15 +232,6 @@ class PytestPluginManager(PluginManager): # API for bootstrapping plugin loading # # - def _envlist(self, varname): - val = os.environ.get(varname, None) - if val is not None: - return val.split(',') - return () - - def consider_env(self): - for spec in self._envlist("PYTEST_PLUGINS"): - self.import_plugin(spec) def consider_setuptools_entrypoints(self): try: @@ -281,13 +272,18 @@ class PytestPluginManager(PluginManager): conftest=True): self.consider_module(conftestmodule) + def consider_env(self): + self._import_plugin_specs(os.environ.get("PYTEST_PLUGINS")) + def consider_module(self, mod): - attr = getattr(mod, "pytest_plugins", ()) - if attr: - if not isinstance(attr, (list, tuple)): - attr = (attr,) - for spec in attr: - self.import_plugin(spec) + self._import_plugin_specs(getattr(mod, "pytest_plugins", None)) + + def _import_plugin_specs(self, spec): + if spec: + if isinstance(spec, str): + spec = spec.split(",") + for import_spec in spec: + self.import_plugin(import_spec) def import_plugin(self, modname): # most often modname refers to builtin modules, e.g. "pytester",