def start_import_stop(
        self,
        cov: Coverage,
        modname: str,
        modfile: str | None = None,
    ) -> ModuleType:
        """Start coverage, import a file, then stop coverage.

        `cov` is started and stopped, with an `import_local_file` of
        `modname` in the middle. `modfile` is the file to import as `modname`
        if it isn't in the current directory.

        The imported module is returned.

        """
        # Here's something I don't understand. I tried changing the code to use
        # the handy context manager, like this:
        #
        #   with cov.collect():
        #       # Import the Python file, executing it.
        #       return import_local_file(modname, modfile)
        #
        # That seemed to work, until 7.4.0 when it made metacov fail after
        # running all the tests.  The deep recursion tests in test_oddball.py
        # seemed to cause something to be off so that a "Trace function
        # changed" error would happen as pytest was cleaning up, failing the
        # metacov runs.  Putting back the old code below fixes it, but I don't
        # understand the difference.

        cov.start()
        try:                                    # pragma: nested
            # Import the Python file, executing it.
            mod = import_local_file(modname, modfile)
        finally:                                # pragma: nested
            # Stop coverage.py.
            cov.stop()
        return mod
Start coverage, import a file, then stop coverage.

        `cov` is started and stopped, with an `import_local_file` of
        `modname` in the middle. `modfile` is the file to import as `modname`
        if it isn't in the current directory.

        The imported module is returned.

        
tests/coveragetest.py