pytest-cov
pytest-cov copied to clipboard
coverage.misc.CoverageException: Couldn't use data file: Safety level may not be changed inside a transaction
Hello and thank you for your work on this project.
A possible incompatibility between pytest-cov and coverage versions greater than 5.0.0 is causing tests to fail in my company's projects. To resolve this problem, our team has pinned coverage to version 4.4 in test-requirements.txt.
After cloning this repo, I noticed that tests are failing when I run them locally and the coverage50 env is set. Have you witnessed this error before and is it possible that coverage ought to be pinned down to < 5.0.0 in the requirements file here?
@patti-c Coverage 5.0 is new, and we are working out the problems. We are not going to pin coverage in pytest-cov, instead we will be trying to fix the problems in coverage.
Can you give us instructions for reproducing the problem? What repo are you running, at which commit, and what commands are you running to see the problem?
@nedbat - Thank you for your response! The command I ran that fails is tox -e py3-pytest52-xdist30-coverage50 on master in pytest-cov. When I run these tests, I see the same error on each failed test that I see in my own projects when attepting to run tox, which is to say:
E and: 'INTERNALERROR> File "/Users/patriciacarter/development/pytest-cov/.tox/py3-pytest52-xdist30-coverage50/lib/python3.6/site-packages/coverage/sqldata.py", line 1025, in execute'
E and: 'INTERNALERROR> return self.con.execute(sql, parameters)'
E and: 'INTERNALERROR> sqlite3.OperationalError: Safety level may not be changed inside a transaction'
@patti-c details like os and python versions would help a lot. Also, paste complete output.
I believe this is the same as https://github.com/nedbat/coveragepy/issues/703. The bug only occurs with Python 3.6.0, it is fixed in Python 3.6.1. If this isn't your scenario, please re-open the issue with more details. Thanks.
@nedbat I am facing same issue on Windows, Python 3.6.4.
.pybuilder\plugins\cpython-3.6.0.final.0\lib\site-packages\coverage\sqldata.py", line 1048, in execute INTERNALERROR> return self.con.execute(sql, parameters) INTERNALERROR> sqlite3.OperationalError: Safety level may not be changed inside a transaction

Could you please help?
@farooqind the path contains .pybuilder\plugins\cpython-3.6.0.final.0 - perhaps your mixing up your interpreters.
Error occurring in Python 2.7.16 using pytest 4.6.9 on FreeBSD 12.
File tox.ini has
[tox]
envlist =
py27
skipsdist = True
[testenv]
commands =
pytest {posargs}
deps =
# pytest 4.6.9 is the last version that supports both python 2.7 and 3.8.
pytest == 4.6.9
pytest-cov
File .coveragerc has
[run]
data_file=/tmp/.coverage
File test_1.py has
def test_1():
pass
Command run as user root
tox -e py27 -c /repo/python/tox.ini -- \
-vv -rA \
/repo/python/tests/test_1.py \
--cov=test1 \
--cov-report=html:/tmp/test1-coverage-report.html
Selections of console output
...
py27 recreate: /repo/python/.tox/py27
py27 installdeps: pytest == 4.6.9, pytest-cov
py27 installed: atomicwrites==1.4.0,attrs==19.3.0,backports.functools-lru-cache==1.6.1,bsddb==0.0.0,configparser==4.0.2,contextlib2==0.6.0.post1,coverage==5.2,funcsigs==1.0.2,importlib-metadata==1.7.0,more-itertools==5.0.0,packaging==20.4,pathlib2==2.3.5,pluggy==0.13.1,py==1.9.0,pyparsing==2.4.7,pytest==4.6.9,pytest-cov==2.10.0,scandir==1.10.0,six==1.15.0,sqlite3==0.0.0,wcwidth==0.2.5,zipp==1.2.0
py27 run-test-pre: PYTHONHASHSEED='1616501112'
py27 run-test: commands[0] | pytest -vv -rA /repo/python/tests/test_1.py --cov=test1 --cov-report=html:/tmp/test1-coverage-report.html
================================================================ test session starts ================================================================
platform freebsd12 -- Python 2.7.16, pytest-4.6.9, py-1.9.0, pluggy-0.13.1 -- /repo/python/.tox/py27/bin/python
cachedir: .tox/py27/.pytest_cache
rootdir: /repo/python
plugins: cov-2.10.0
...
INTERNALERROR> CoverageException: Couldn't use data file '/tmp/.coverage.host.8751.398447': Safety level may not be changed inside a transaction
Run on FreeBSD 12.
updated reproduction attempt
In case anyone ever looks, I was unable to reproduce this error using docker. :-(
$ docker run -it python:2.7 bash -l
# within docker instance
$ python -m pip install tox
$ echo '
[tox]
envlist =
py27
skipsdist = True
[testenv]
commands =
pytest {posargs}
deps =
# pytest 4.6.9 is the last version that supports both python 2.7 and 3.8.
pytest == 4.6.9
pytest-cov
' > tox.ini
$ echo '
[run]
data_file=/tmp/.coverage
' > .coveragerc
$ echo '
def test_A():
pass
' > test_1.py
$ tox -e py27 -c ./tox.ini -- ./test1.py -rA --cov=test1 --cov-report=html:/tmp/test1-coverage-report.html
What does your test file contain? Also what OS? I guess you cannot reproduce on the debian-based python image cause you have a different os, you might want to try getting a docker image closer to your os?
What does your test file contain?
I updated the comment.
Also what OS?
FreeBSD 12. I updated the comment.
a docker image closer to your os
Unfortunately it's not a Linux-based OS.