def lint_codeblock(styleguide, tmp_path):
    """Fixture which runs the styleguide's `lint` subcommand when executed."""

    def run_linter(
        codeblock,
        *styleguide_args,
        # We ignore unused import warnings as most of the codeblocks which produce this warning
        # are just demonstrations of bad/good imports. Adding usage of the imports would add
        # code to trivial examples, detracting from the interesting lines.
        ignore_unused_imports=True,
    ):

        extend_ignore = [
            # Undefined name. Defining all the names in each example would detract from the
            # interesting lines.
            "F821",
            # Missing docstring in XYZ.
            "D1",
        ]
        if ignore_unused_imports:
            extend_ignore.append("F401")
        styleguide_args += ("--extend-ignore", ",".join(extend_ignore))

        test_file = tmp_path / "test.py"
        test_file.write_text(codeblock.contents, encoding="utf-8")
        return styleguide("lint", *styleguide_args, test_file)

    return run_linter