I have a python wsgi app that is configured to be run with uwsgi which is installed in the app's virtual environment. The app's main functionality is to retrieve files from a database. I need to test this functionality while running the app with uwsgi. At the same time I need to mock the outputs of the function that connects to the database. When running uwsgi this proves to be a hard (impossible?) thing to do.
The main app is called app.py. In the same directory there's a tests module (dir with init.py) with tests. I try to patch the function's output with patch (form unittest.mock), then open the web-page with selenium in a test case, all while uwsgi is running. But uwsgi's ouput seems unaffected by the patching, uwsgi just uses the real function from app.py.
What could I possibly do to achieve the required behaviour? I need to test how the app works with uwsgi, and at the same time can not use any database.
This seems like you're mixing up different levels of testing. Mocking/patching is appropriate for a unit test, where you test a function in isolation. What you're describing is an integration test; here, rather than patching, you should set up your app to run with a test database.
Unittest + Mock + UWSGI