'Given an importhook, mark for rewrite any top-level
modules or packages in the distribution package for
all pytest plugins.'

def _mark_plugins_for_rewrite(self, hook):

    import pkg_resources
    self.pluginmanager.rewrite_hook = hook
    metadata_files = ('RECORD', 'SOURCES.txt')
    package_files = (entry.split(',')[0] for entrypoint in pkg_resources.iter_entry_points('pytest11') for metadata in metadata_files for entry in entrypoint.dist._get_metadata(metadata))
    for name in _iter_rewritable_modules(package_files):
        hook.mark_rewrite(name)
