'Install the PEP 302 import hook if using assertion re-writing.
Needs to parse the --assert=<mode> option from the commandline
and find all the installed plugins to mark them for re-writing
by the importhook.'

def _consider_importhook(self, args, entrypoint_name):

    (ns, unknown_args) = self._parser.parse_known_and_unknown_args(args)
    mode = ns.assertmode
    if (mode == 'rewrite'):
        try:
            hook = _pytest.assertion.install_importhook(self)
        except SystemError:
            mode = 'plain'
        else:
            import pkg_resources
            self.pluginmanager.rewrite_hook = hook
            for entrypoint in pkg_resources.iter_entry_points('pytest11'):
                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)
    self._warn_about_missing_assertion(mode)
