From ce0ff0040f2c05f90270e84e519df68292268bf4 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 20 May 2017 04:21:08 -0400 Subject: [PATCH] Reindent and add docstring --- _pytest/config.py | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/_pytest/config.py b/_pytest/config.py index 5abb13d5a..0485d5381 100644 --- a/_pytest/config.py +++ b/_pytest/config.py @@ -999,24 +999,29 @@ class Config(object): self._warn_about_missing_assertion(mode) def _mark_plugins_for_rewrite(self, hook): - import pkg_resources - self.pluginmanager.rewrite_hook = hook - for entrypoint in pkg_resources.iter_entry_points('pytest11'): - # 'RECORD' available for plugins installed normally (pip install) - # 'SOURCES.txt' available for plugins installed in dev mode (pip install -e) - # for installed plugins 'SOURCES.txt' returns an empty list, and vice-versa - # so it shouldn't be an issue - for metadata in ('RECORD', 'SOURCES.txt'): - for entry in entrypoint.dist._get_metadata(metadata): - fn = entry.split(',')[0] - is_simple_module = os.sep not in fn and fn.endswith('.py') - is_package = fn.count(os.sep) == 1 and fn.endswith('__init__.py') - if is_simple_module: - module_name, ext = os.path.splitext(fn) - hook.mark_rewrite(module_name) - elif is_package: - package_name = os.path.dirname(fn) - hook.mark_rewrite(package_name) + """ + Given an importhook, mark for rewrite any top-level + modules or packages in the distribution package for + all pytest plugins. + """ + import pkg_resources + self.pluginmanager.rewrite_hook = hook + for entrypoint in pkg_resources.iter_entry_points('pytest11'): + # 'RECORD' available for plugins installed normally (pip install) + # 'SOURCES.txt' available for plugins installed in dev mode (pip install -e) + # for installed plugins 'SOURCES.txt' returns an empty list, and vice-versa + # so it shouldn't be an issue + for metadata in ('RECORD', 'SOURCES.txt'): + for entry in entrypoint.dist._get_metadata(metadata): + fn = entry.split(',')[0] + is_simple_module = os.sep not in fn and fn.endswith('.py') + is_package = fn.count(os.sep) == 1 and fn.endswith('__init__.py') + if is_simple_module: + module_name, ext = os.path.splitext(fn) + hook.mark_rewrite(module_name) + elif is_package: + package_name = os.path.dirname(fn) + hook.mark_rewrite(package_name) def _warn_about_missing_assertion(self, mode): try: