remove some redundancy when parsing import spec
--HG-- branch : plugin_no_pytest
This commit is contained in:
		
							parent
							
								
									95dd2eb1da
								
							
						
					
					
						commit
						feb4b2249a
					
				| 
						 | 
					@ -232,15 +232,6 @@ class PytestPluginManager(PluginManager):
 | 
				
			||||||
    # API for bootstrapping plugin loading
 | 
					    # 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):
 | 
					    def consider_setuptools_entrypoints(self):
 | 
				
			||||||
        try:
 | 
					        try:
 | 
				
			||||||
| 
						 | 
					@ -281,13 +272,18 @@ class PytestPluginManager(PluginManager):
 | 
				
			||||||
                         conftest=True):
 | 
					                         conftest=True):
 | 
				
			||||||
            self.consider_module(conftestmodule)
 | 
					            self.consider_module(conftestmodule)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def consider_env(self):
 | 
				
			||||||
 | 
					        self._import_plugin_specs(os.environ.get("PYTEST_PLUGINS"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def consider_module(self, mod):
 | 
					    def consider_module(self, mod):
 | 
				
			||||||
        attr = getattr(mod, "pytest_plugins", ())
 | 
					        self._import_plugin_specs(getattr(mod, "pytest_plugins", None))
 | 
				
			||||||
        if attr:
 | 
					
 | 
				
			||||||
            if not isinstance(attr, (list, tuple)):
 | 
					    def _import_plugin_specs(self, spec):
 | 
				
			||||||
                attr = (attr,)
 | 
					        if spec:
 | 
				
			||||||
            for spec in attr:
 | 
					            if isinstance(spec, str):
 | 
				
			||||||
                self.import_plugin(spec)
 | 
					                spec = spec.split(",")
 | 
				
			||||||
 | 
					            for import_spec in spec:
 | 
				
			||||||
 | 
					                self.import_plugin(import_spec)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def import_plugin(self, modname):
 | 
					    def import_plugin(self, modname):
 | 
				
			||||||
        # most often modname refers to builtin modules, e.g. "pytester",
 | 
					        # most often modname refers to builtin modules, e.g. "pytester",
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue