def make_pyc(self, **kwargs: Any) -> str:
        """Create a .pyc file, and return the path to it."""
        self.make_file("compiled.py", """\
            def doit():
                print("I am here!")

            doit()
            """)
        compileall.compile_dir(".", quiet=True, **kwargs)
        os.remove("compiled.py")

        # Find the .pyc file!
        return str(next(pathlib.Path(".").rglob("compiled*.pyc")))
Create a .pyc file, and return the path to it.
tests/test_execfile.py