pytest-dev / pytest-cov

Coverage plugin for pytest.
MIT License
1.76k stars 212 forks source link

coverage.misc.CoverageException: Couldn't use data file: Safety level may not be changed inside a transaction #404

Open farooqind opened 4 years ago

farooqind commented 4 years ago

In continuation of https://github.com/pytest-dev/pytest-cov/issues/379:

@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

image

Could you please help?

nedbat commented 4 years ago

Can you provide us with a reproducible scenario?

farooqind commented 4 years ago

@nedbat what exactly you require?

I am using this in build.py : use_plugin('pypi:pybuilder_pytest_coverage')

Python version is 3.6.4 on windows Pybuilder version : 0.12.6

nedbat commented 4 years ago

We need:

farooqind commented 4 years ago

I am using client's code so that cannot be shared.

I have installed python, pybuilder on local machine (windows).

This is pytest version 5.4.1, imported from c:\users\XXX\appdata\local\programs\python\python36\lib\site-packages\pytest__init__.py setuptools registered plugins: pytest-cov-2.8.1 at c:\users\XXXX\appdata\local\programs\python\python36\lib\site-packages\pytest_cov\plugin.py pytest-pythonpath-0.7.3 at c:\users\XXXX\appdata\local\programs\python\python36\lib\site-packages\pytest_pythonpath.py

Also using pytest.ini: [pytest] addopts = -v --cov-report term --cov-report html:htmlcov --cov-report xml --cov-fail-under=0

command to run : "pyb_ --debug"

nedbat commented 4 years ago

Perhaps you could put together a small repo that shows the same problem? I'm not familiar with pybuilder.

farooqind commented 4 years ago

So I tried on

  1. Linux, Python version 3.6.9 => It works
  2. Windows, Python version 3.6.8 => It works
  3. Windows, Python version 3.6.4 => It gives error mentioned in issue

So basically if you run a simple test using pytest and coverage on Python verison 3.6.4, you may get this issue.

nedbat commented 4 years ago

I have nothing to try. I can't invent your scenario.

farooqind commented 4 years ago

You can just create a simple python project and a pytest file. Use python version 3.6.4 and run the build with pybuilder including pytest and coverage. Even if I create a project for you, unless you use python 3.6.4, issue won’t occur.

On 30-Apr-2020, at 7:57 PM, Ned Batchelder notifications@github.com wrote:

I have nothing to try. I can't invent your scenario.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

farooqind commented 4 years ago

I will create project in github and share with you. Hope that helps.

On 30-Apr-2020, at 9:34 PM, Ned Batchelder notifications@github.com wrote:

Reopened #404.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

farooqind commented 4 years ago

@nedbat I have shared a repo with you with sample project.

nedbat commented 4 years ago

Thanks, but please:

farooqind commented 4 years ago

I installed only python and pybuilder. Pytest and pytest-cov is intalled automatically during build. Command to run: “pyb_ —debug”

Could you please see if you are getting error? If yes then I will make public or give access to whoever wants.

On 03-May-2020, at 8:33 AM, Ned Batchelder notifications@github.com wrote:

Thanks, but please:

Make the repo public so that other people can help Provide instructions about what to install (I guessed: pytest, pybuilder, pytest-cov) Provide instructions about how to run the tests. I typed "pytest", and got an error: "No module named 'bar'". — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

nedbat commented 4 years ago

I am not seeing an error, but I am not on Windows. If this happens with 3.6.4, but does not happen with 3.6.8, that might point to something being fixed in Python.

Please make the reproducible scenario public, with instructions, so that someone can look into it who has better access to Windows than I do.

Murtaza-SerpentCS commented 4 years ago

I am also facing this problem: coverage html

Couldn't use data file '/home/workspace/openerp/13.0/.coverage': Safety level may not be changed inside a transaction

farooqind commented 4 years ago

Which version of python you are using and also which platform?

On 08-May-2020, at 12:25 AM, Murtaza Mithaiwala notifications@github.com wrote:

I am also facing this problem: coverage html

Couldn't use data file '/home/workspace/openerp/13.0/.coverage': Safety level may not be changed inside a transaction

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

Murtaza-SerpentCS commented 4 years ago

Python 3.6.0 ubuntu

nedbat commented 4 years ago

3.6.0 specifically had an issue: https://github.com/nedbat/coveragepy/issues/703 Can you update your Python version?

sodiray commented 4 years ago

I opened an older python 3 project today on my Mac with these dependencies installed

pytest==5.1.2
pytest-cov==2.7.1

when running this test command

pytest --cov=project --cov-report term:skip-covered --cov-fail-under=75 --cov-report=html project/

was getting this error

INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/Users/rayepps/projects/project/venv/lib/python3.6/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

I deleted the virtual environment (venv) and recreated it with python 3.8 (it was previously created with the default python3 on my machine - 3.6) reinstalled the dependencies and the tests ran as expected with coverage.