coveragepy
coveragepy copied to clipboard
An err with .coverage database
Hi,First of all, thanks for this library!
The question
When I was testing with Coverage.py, something went wrong:
Traceback (most recent call last): File "/home/bromiao/.local/lib/python3.8/site-packages/coverage/sqldata.py", line 1107, in execute return self.con.execute(sql, parameters) sqlite3.OperationalError: no such table: arc
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "/home/bromiao/.local/lib/python3.8/site-packages/coverage/sqldata.py", line 1112, in execute return self.con.execute(sql, parameters) sqlite3.OperationalError: no such table: arc
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "test.py", line 22, in
I used coverage.py like this:
cov = coverage.Coverage()
cov.set_option("run:branch", True)
cov.start()
do_something()
cov.stop()
cov.json_report(outfile=report_str, pretty_print=True)
This file named “usingcoverage.py”
When testing , I used threading and subprocess like this: Threading:
t=threading.Thread(target=target_func,args=(arg,))
t.start()
Subprocess:
def target_func(self,arg):
ret = subprocess.run(“python3 usingcoverage.py”, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding="utf-8",timeout=100)
I think this might be causing the concurrent use of the .coverage database to throw the error
I did my work in Ubuntu 20.04, python 3.8.10 Coverage.py version 6.3.2 with C extension
Can you provide the full code to reproduce the problem? It would help to explain why you are using the API instead of the command-line interface, why you are using a subprocess from Python, and why you are using a thread to run the subprocess.
The full code is sample. Can I use e-mail?
Have you got the e-mail?
Hi, I also have this problem. It is not happening consistently, using the PYTEST_ADDOPTS="--cov --cov-report=html" python setup.py test
command line.
Experiencing on wsl Ubuntu 20.04.5 with python 3.9.13, coverage==6.5.0, pytest-cov==2.7.1 and pytest==5.0.0
I get a warning instead of an error (paths abbreviated):
(...)/.virtualenv/lib/python3.9/site-packages/coverage/report.py:87: CoverageWarning: Couldn't parse '(...)/somepackage/somefile.py': Couldn't use data file '(...)/.coverage': no such table: arc (couldnt-parse)
coverage._warn(msg, slug="couldnt-parse")
I don't know about the pytest, But would you like to see if the ".coverage" data file exist? And if your ".coverage" data file is rewriting when you excuting your command?
Hi, I figured out the problem with my .coverage file. I was launching my tests from a commandline in VSCode and due to some reason, VSCode was launching pytest discovery at the same time, resulting in the coverage file being overwritten.
I used sqlite database viewer to look into the .coverage file to find this in the meta
table:
sys_argv | ['/home/<user_name>/.vscode-server/extensions/ms-python.python-2022.18.2/pythonFiles/testing_tools/run_adapter.py', 'discover', 'pytest', '--', '--rootdir', '/home/<user_name>/dev/<project_name>', '-s', '--cache-clear', '-c=setup.cfg'] |
---|---|
version | 6.5.0 |
when | 2022-11-10 17:58:54 |
has_arcs | 1 |
While when the coverage was alright, the meta table looks like this:
sys_argv | ['setup.py'] |
---|---|
version | 6.5.0 |
when | 2022-11-10 17:18:15 |
has_arcs | 1 |
Adding --no-cov
to the VSCode setting "python.testing.pytestArgs"
fixed it for me.
I don't have a way to reproduce this yet. If you can provide me with code I can run, I can re-open it.
I'm sorry for that, this is my problem. I started multiple programs at the same time, but they used the same database ".coverage". Writing different coverage data over a short period of time causes this problem. Then I tried to use different database for each program. Finally the problem was solved.