# Buggy code
def execute(self, sql, parameters=()):
    """Same as :meth:`python:sqlite3.Connection.execute`."""
    if self.debug:
        tail = " with {!r}".format(parameters) if parameters else ""
        self.debug.write("Executing {!r}{}".format(sql, tail))
    try:
        return self.con.execute(sql, parameters)
    except sqlite3.Error as exc:
        raise CoverageException(
            "Couldn't use data file {!r}: {}".format(self.filename, exc)
        )


# Traceback (sqlite3.DatabaseError)
Traceback (most recent call last):
File "/Users/ellbosch/Repos/mssql-cli/.tox/py37/lib/python3.7/site-packages/coverage/sqldata.py", line 1025, in execute
return self.con.execute(sql, parameters)
sqlite3.DatabaseError: file is not a database

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/ellbosch/Repos/mssql-cli/.tox/py37/bin/pytest", line 8, in <module>
sys.exit(main())
File "/Users/ellbosch/Repos/mssql-cli/.tox/py37/lib/python3.7/site-packages/_pytest/config/__init__.py", line 72, in main
config = _prepareconfig(args, plugins)
File "/Users/ellbosch/Repos/mssql-cli/.tox/py37/lib/python3.7/site-packages/_pytest/config/__init__.py", line 223, in _prepareconfig
pluginmanager=pluginmanager, args=args
File "/Users/ellbosch/Repos/mssql-cli/.tox/py37/lib/python3.7/site-packages/pluggy/hooks.py", line 286, in __call__
return self._hookexec(self, self.get_hookimpls(), kwargs)
File "/Users/ellbosch/Repos/mssql-cli/.tox/py37/lib/python3.7/site-packages/pluggy/manager.py", line 93, in _hookexec
return self._inner_hookexec(hook, methods, kwargs)
File "/Users/ellbosch/Repos/mssql-cli/.tox/py37/lib/python3.7/site-packages/pluggy/manager.py", line 87, in <lambda>
firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
File "/Users/ellbosch/Repos/mssql-cli/.tox/py37/lib/python3.7/site-packages/pluggy/callers.py", line 203, in _multicall
gen.send(outcome)
File "/Users/ellbosch/Repos/mssql-cli/.tox/py37/lib/python3.7/site-packages/_pytest/helpconfig.py", line 89, in pytest_cmdline_parse
config = outcome.get_result()
File "/Users/ellbosch/Repos/mssql-cli/.tox/py37/lib/python3.7/site-packages/pluggy/callers.py", line 80, in get_result
raise ex[1].with_traceback(ex[2])
File "/Users/ellbosch/Repos/mssql-cli/.tox/py37/lib/python3.7/site-packages/pluggy/callers.py", line 187, in _multicall
res = hook_impl.function(*args)
File "/Users/ellbosch/Repos/mssql-cli/.tox/py37/lib/python3.7/site-packages/_pytest/config/__init__.py", line 793, in pytest_cmdline_parse
self.parse(args)
File "/Users/ellbosch/Repos/mssql-cli/.tox/py37/lib/python3.7/site-packages/_pytest/config/__init__.py", line 999, in parse
self._preparse(args, addopts=addopts)
File "/Users/ellbosch/Repos/mssql-cli/.tox/py37/lib/python3.7/site-packages/_pytest/config/__init__.py", line 957, in _preparse
early_config=self, args=args, parser=self._parser
File "/Users/ellbosch/Repos/mssql-cli/.tox/py37/lib/python3.7/site-packages/pluggy/hooks.py", line 286, in __call__
return self._hookexec(self, self.get_hookimpls(), kwargs)
File "/Users/ellbosch/Repos/mssql-cli/.tox/py37/lib/python3.7/site-packages/pluggy/manager.py", line 93, in _hookexec
return self._inner_hookexec(hook, methods, kwargs)
File "/Users/ellbosch/Repos/mssql-cli/.tox/py37/lib/python3.7/site-packages/pluggy/manager.py", line 87, in <lambda>
firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
File "/Users/ellbosch/Repos/mssql-cli/.tox/py37/lib/python3.7/site-packages/pluggy/callers.py", line 208, in _multicall
return outcome.get_result()
File "/Users/ellbosch/Repos/mssql-cli/.tox/py37/lib/python3.7/site-packages/pluggy/callers.py", line 80, in get_result
raise ex[1].with_traceback(ex[2])
File "/Users/ellbosch/Repos/mssql-cli/.tox/py37/lib/python3.7/site-packages/pluggy/callers.py", line 187, in _multicall
res = hook_impl.function(*args)
File "/Users/ellbosch/Repos/mssql-cli/.tox/py37/lib/python3.7/site-packages/pytest_cov/plugin.py", line 118, in pytest_load_initial_conftests
plugin = CovPlugin(early_config.known_args_namespace, early_config.pluginmanager)
File "/Users/ellbosch/Repos/mssql-cli/.tox/py37/lib/python3.7/site-packages/pytest_cov/plugin.py", line 164, in __init__
self.start(engine.Central)
File "/Users/ellbosch/Repos/mssql-cli/.tox/py37/lib/python3.7/site-packages/pytest_cov/plugin.py", line 186, in start
self.cov_controller.start()
File "/Users/ellbosch/Repos/mssql-cli/.tox/py37/lib/python3.7/site-packages/pytest_cov/engine.py", line 187, in start
self.cov.load()
File "/Users/ellbosch/Repos/mssql-cli/.tox/py37/lib/python3.7/site-packages/coverage/control.py", line 387, in load
self._data.read()
File "/Users/ellbosch/Repos/mssql-cli/.tox/py37/lib/python3.7/site-packages/coverage/sqldata.py", line 741, in read
with self._connect():       # TODO: doesn't look right
File "/Users/ellbosch/Repos/mssql-cli/.tox/py37/lib/python3.7/site-packages/coverage/sqldata.py", line 296, in _connect
self._open_db()
File "/Users/ellbosch/Repos/mssql-cli/.tox/py37/lib/python3.7/site-packages/coverage/sqldata.py", line 264, in _open_db
self._read_db()
File "/Users/ellbosch/Repos/mssql-cli/.tox/py37/lib/python3.7/site-packages/coverage/sqldata.py", line 268, in _read_db
with self._dbs[get_thread_id()] as db:
File "/Users/ellbosch/Repos/mssql-cli/.tox/py37/lib/python3.7/site-packages/coverage/sqldata.py", line 1008, in __enter__
self._connect()
File "/Users/ellbosch/Repos/mssql-cli/.tox/py37/lib/python3.7/site-packages/coverage/sqldata.py", line 996, in _connect
self.execute("pragma journal_mode=off").close()
File "/Users/ellbosch/Repos/mssql-cli/.tox/py37/lib/python3.7/site-packages/coverage/sqldata.py", line 1027, in execute
raise CoverageException("Couldn't use data file {!r}: {}".format(self.filename, exc))
coverage.misc.CoverageException: Couldn't use data file '/Users/ellbosch/Repos/mssql-cli/.coverage': file is not a database
Command '['pytest', '-l', '--cov', 'mssqlcli', '--doctest-modules', '--junitxml=junit/test-6d62ae30-2031-11ea-80ec-3af9d39e6caa-results.xml', '--cov-report=xml', '--cov-report=html', '--cov-append', '-o', 'junit_suite_name=pytest-3.7.4', '-s', '-m', 'not unstable', 'tests/jsonrpc']' returned non-zero exit status 1.
ERROR: InvocationError for command /Users/ellbosch/Repos/mssql-cli/.tox/py37/bin/python build.py unit_test (exited with code 1)

# Fixed code
def execute(self, sql, parameters=()):
    """Same as :meth:`python:sqlite3.Connection.execute`."""
    if self.debug:
        tail = " with {!r}".format(parameters) if parameters else ""
        self.debug.write("Executing {!r}{}".format(sql, tail))
    try:
        return self.con.execute(sql, parameters)
    except sqlite3.Error as exc:
        msg = str(exc)
        try:
            # `execute` is the first thing we do with the database, so try
            # hard to provide useful hints if something goes wrong now.
            with open(self.filename, "rb") as bad_file:
                cov4_sig = b"!coverage.py: This is a private format"
                if bad_file.read(len(cov4_sig)) == cov4_sig:
                    msg = (
                        "Looks like a coverage 4.x data file. "
                        "Are you mixing versions of coverage?"
                    )
        except Exception:
            pass
        raise CoverageException(
            "Couldn't use data file {!r}: {}".format(self.filename, msg)
        )