6

I know there are more similar questions but none of them solve the problem that I am having. I have assembled a very basic Python application with Flask:

from flask import Flask

app = Flask(__name__)

@app.route('/')
def index():
    return 'HELLO WORLD!'

app.run(host='0.0.0.0', port=8000)

Where older I have created a false unit test:

def calc(x, y):
    return x + y

def test_calc():
    assert 5 == calc(2, 3)

What I really want to create is a CI that creates a docker image, do the tests, and then post the docker image to Docker Hub but running this command to run the tests docker-compose run app sh -c "pytest test.py --cov -p no:cacheprovider" I get the error:

test.py .                                                                                                                                                   [100%]
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/usr/local/lib/python3.8/site-packages/_pytest/main.py", line 240, in wrap_session
INTERNALERROR>     session.exitstatus = doit(config, session) or 0
INTERNALERROR>   File "/usr/local/lib/python3.8/site-packages/_pytest/main.py", line 296, in _main
INTERNALERROR>     config.hook.pytest_runtestloop(session=session)
INTERNALERROR>   File "/usr/local/lib/python3.8/site-packages/pluggy/hooks.py", line 286, in __call__
INTERNALERROR>     return self._hookexec(self, self.get_hookimpls(), kwargs)
INTERNALERROR>   File "/usr/local/lib/python3.8/site-packages/pluggy/manager.py", line 93, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/usr/local/lib/python3.8/site-packages/pluggy/manager.py", line 84, in <lambda>
INTERNALERROR>     self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
INTERNALERROR>   File "/usr/local/lib/python3.8/site-packages/pluggy/callers.py", line 203, in _multicall
INTERNALERROR>     gen.send(outcome)
INTERNALERROR>   File "/usr/local/lib/python3.8/site-packages/pytest_cov/plugin.py", line 271, in pytest_runtestloop
INTERNALERROR>     self.cov_controller.finish()
INTERNALERROR>   File "/usr/local/lib/python3.8/site-packages/pytest_cov/engine.py", line 44, in ensure_topdir_wrapper
INTERNALERROR>     return meth(self, *args, **kwargs)
INTERNALERROR>   File "/usr/local/lib/python3.8/site-packages/pytest_cov/engine.py", line 229, in finish
INTERNALERROR>     self.cov.stop()
INTERNALERROR>   File "/usr/local/lib/python3.8/site-packages/coverage/control.py", line 658, in save
INTERNALERROR>     data = self.get_data()
INTERNALERROR>   File "/usr/local/lib/python3.8/site-packages/coverage/control.py", line 716, in get_data
INTERNALERROR>     if self._collector and self._collector.flush_data():
INTERNALERROR>   File "/usr/local/lib/python3.8/site-packages/coverage/collector.py", line 442, in flush_data
INTERNALERROR>     self.covdata.add_lines(self.mapped_file_dict(self.data))
INTERNALERROR>   File "/usr/local/lib/python3.8/site-packages/coverage/sqldata.py", line 437, in add_lines
INTERNALERROR>     self._choose_lines_or_arcs(lines=True)
INTERNALERROR>   File "/usr/local/lib/python3.8/site-packages/coverage/sqldata.py", line 494, in _choose_lines_or_arcs
INTERNALERROR>     with self._connect() as con:
INTERNALERROR>   File "/usr/local/lib/python3.8/site-packages/coverage/sqldata.py", line 299, in _connect
INTERNALERROR>     self._create_db()
INTERNALERROR>   File "/usr/local/lib/python3.8/site-packages/coverage/sqldata.py", line 248, in _create_db
INTERNALERROR>     with db:
INTERNALERROR>   File "/usr/local/lib/python3.8/site-packages/coverage/sqldata.py", line 1026, in __enter__
INTERNALERROR>     self._connect()
INTERNALERROR>   File "/usr/local/lib/python3.8/site-packages/coverage/sqldata.py", line 1008, in _connect
INTERNALERROR>     self.con = sqlite3.connect(filename, check_same_thread=False)
INTERNALERROR> sqlite3.OperationalError: unable to open database file
Kevimuxx69
  • 109
  • 1
  • 7
  • The code you show doesn't mention a database at all. Is there more of the application or test setup you haven't included? – David Maze Sep 30 '20 at 13:25
  • @DavidMaze No, it's just that. The rest is the docker-compose and the Dockerfile but i don't mention any database – Kevimuxx69 Sep 30 '20 at 13:39
  • Could you add your Dockerfile to the question please? – oschlueter Sep 30 '20 at 15:41
  • 1
    hi @Kevimuxx69 were you able to solve this issue? I am facing a similar issue in CircleCI with `sqlite3.OperationalError: unable to open database file` . I am using python:3.8-alpine image to build the application – anandg112 Dec 24 '20 at 23:08
  • 1
    I had this issue with Docker on Github Actions and "solved" it by running the docker test command as root; `docker-compose run -u root --rm web \ bin/wait-for-postgres.sh coverage run --source=idp_data manage.py test` – Paul Watson Feb 05 '21 at 09:25
  • This still fails the Ci with exit code 5 – onlinejudge95 Jul 05 '21 at 10:41

1 Answers1

0

I had the same issue. User from container can't create files in working dir. So, executing as root could solve issue. You could also change working dir or add permissions to user.