Issue
I'm currently working on a Flask application that utilizes Flask-RESTful to create an API, and it's working perfectly when I run it. However, when trying to set up tests using Pytest, I get the following error:
ImportError: cannot import name '_request_ctx_stack' from 'flask
This happens whenever I call "pytest" on the terminal. It can even be "pytest -h", it still raises the Exception.
The application works just fine when I call "py main.py". I've been testing it with Postman and a side-script I wrote using the requests package. I have never seen this error before.
By reading about the error itself I found some topics where the problem seemed to be the version of Flask. I didn't find anything specific to Pytest, though, and it doesn't seem to be my case considering the application runs as intended on it's own.
So far, I tried:
- Downgrading Flask to an earlier version;
- Removing every reference to Flask from the tests folder and trying to test a basic
assert True
; - Verifying that neither Pytest nor Flask are installed globally (I've seen some suggestions that this might have been the problem);
- Recreating my virtual environment.
None of this worked so far, and I'm almost sure the problem doesn't have anything to do with my Flask installation (otherwise, the API wouldn't run, I suppose).
Solution
In my case, uninstalling pytest-flask
package worked. Not sure what it does, though.
Answered By - csant
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.