Karl Dubost: Week notes - 2020 w07 - worklog - flask blueprint |
A string of secondary issues have been plaguing our restart of anonymous reporting on webcompat.com.
fixed! Dependencies upgrade
Simple! I had forgotten to handle the case of private issue with milestone accepted being closed. This erased a valid moderated issue. Not good. So we fixed it. This is now working.
There was a solution to the issue we had last week about our string which is not a boolean: strtobool. Thanks to rik. Implementation details. Values include on
and off
. Neat!
In the process of trying to improve the project, I looked at the results of coverage on the project. I was pleasantly surprised for some areas of the code. But I also decided to open a couple of issues related to other parts. The more and better tests we have, the more robust the project will be.
While running coverage, I also stumbled upon this sentence in the documentation:
Nose has been unmaintained for a long time. You should seriously consider adopting a different test runner.
So I decided to create an issue specific on switching from nosetests to pytest.
And I started to work on that. It led to an interesting number of new breakages and warnings. First pytest is working better with an installable code.
pip install -e .
So I created a very simple and basic setup.py
then I ran to an issue that has bitten me in the past: flask blueprint.
Basically our code has this kind of constructs. subtree to make it simpler.
-- webcompat |-- __init__.py |-- form.py |-- api | |-- __init__.py | |-- uploads.py | |-- endpoints.py … |-- helpers.py |-- views.py
so in webcompat/__init__.py
from webcompat.api.endpoints import api app = Flask(__name__, static_url_path='') app.register_blueprint(api)
and in webcompat/api/endpoints/__init__.py
from webcompat.helpers import cool_feature api = Blueprint('api', __name__, url_prefix='/api') @api.route('blah') def somewhere(foo): """blablah""" yeah = cool_feature()
So what is happening here? The module and the blueprint share the same name. So if in a test we need to mock cool_feature:
with patch('webcompat.api.endpoints.cool_feature') as mock_cool:
We need to remember that when mocking, we do not mock the feature where it has been defined (aka webcompat.helpers.cool_feature
) but where it has been imported (aka webcompat.api.endpoints.cool_feature
). We will not be able to mock in this case because there will be a conflict of names. The error will be:
E AttributeError: 'Blueprint' object has no attribute 'endpoints'
because the named webcompat.api
blueprint has no attribute endpoints
while the module webcompat.api
has one.
So I will need to fix this next week.
I also needed to changed CircleCI configuration to be able to run with pytest, even if it breaks for now.
Friday I did some diagnosis and I'll do next monday and probably tuesday too.
Otsukare!
Комментировать | « Пред. запись — К дневнику — След. запись » | Страницы: [1] [Новые] |