Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix coverage detection on SQLAlchemy calls #26

Merged
merged 1 commit into from Jan 17, 2022

Conversation

florimondmanca
Copy link
Collaborator

@florimondmanca florimondmanca commented Jan 17, 2022

Suite de #24

Cette PR corrige le comportement de la détection de coverage pour les lignes suivant un appel à la BDD.

En effet, le support de async dans SQLAlchemy fait appel à greenlet, une implémentation de coroutines pour Python. Coverage.py a besoin d'un flag explicite pour être compatible avec greenlet (par défaut concurrency = thread seulement), sinon les lignes suivant un appel à greenlet peuvent ne pas être détectées (voir nedbat/coveragepy#1082), comme c'est le cas ici.

Le coverage monte 91% -> 97%, car des lignes étaient ignorées à cause de ce pb. :-)

============================= test session starts ==============================
platform linux -- Python 3.8.12, pytest-6.2.5, py-1.11.0, pluggy-1.0.0
rootdir: /home/florimond/dev/prj-catalogue/catalogage-donnees, configfile: setup.cfg, testpaths: tests
plugins: asyncio-0.16.0, cov-3.0.0, anyio-3.4.0
collected 17 items

tests/test_app.py .                                                      [  5%]
tests/api/test_auth.py ..............                                    [ 88%]
tests/api/test_datasets.py .                                             [ 94%]
tests/domain/test_datasets.py .                                          [100%]

---------- coverage: platform linux, python 3.8.12-final-0 -----------
Name                                             Stmts   Miss  Cover   Missing
------------------------------------------------------------------------------
server/__init__.py                                   0      0   100%
server/api/__init__.py                               0      0   100%
server/api/app.py                                   11      0   100%
server/api/auth/__init__.py                          2      0   100%
server/api/auth/dependencies.py                     14      0   100%
server/api/auth/routes.py                           29      3    90%   34-37
server/api/auth/schemas.py                          10      0   100%
server/api/datasets/__init__.py                      2      0   100%
server/api/datasets/routes.py                       37      0   100%
server/api/datasets/schemas.py                       7      0   100%
server/api/routes.py                                11      0   100%
server/api/security.py                               2      0   100%
server/application/__init__.py                       0      0   100%
server/application/auth/__init__.py                  0      0   100%
server/application/auth/commands.py                  6      0   100%
server/application/auth/handlers.py                 25      2    92%   26-27
server/application/auth/queries.py                   4      0   100%
server/application/datasets/__init__.py              0      0   100%
server/application/datasets/commands.py              6      0   100%
server/application/datasets/handlers.py             23      0   100%
server/application/datasets/queries.py               8      0   100%
server/config/__init__.py                            2      0   100%
server/config/di.py                                 48      0   100%
server/config/settings.py                           22      0   100%
server/domain/__init__.py                            0      0   100%
server/domain/auth/__init__.py                       0      0   100%
server/domain/auth/entities.py                       7      0   100%
server/domain/auth/exceptions.py                     6      0   100%
server/domain/auth/repositories.py                   8      0   100%
server/domain/common/__init__.py                     0      0   100%
server/domain/common/exceptions.py                   5      0   100%
server/domain/common/types.py                        1      0   100%
server/domain/datasets/__init__.py                   0      0   100%
server/domain/datasets/entities.py                   7      0   100%
server/domain/datasets/exceptions.py                 3      0   100%
server/domain/datasets/repositories.py               9      0   100%
server/infrastructure/__init__.py                    0      0   100%
server/infrastructure/adapters/__init__.py           0      0   100%
server/infrastructure/adapters/json.py               9      4    56%   7-9, 13
server/infrastructure/adapters/messages.py          18      2    89%   26-27
server/infrastructure/auth/__init__.py               0      0   100%
server/infrastructure/auth/module.py                 7      0   100%
server/infrastructure/auth/repositories.py          34      4    88%   43-46
server/infrastructure/database.py                   13      0   100%
server/infrastructure/datasets/__init__.py           0      0   100%
server/infrastructure/datasets/module.py             7      0   100%
server/infrastructure/datasets/repositories.py      40      0   100%
server/main.py                                       4      4     0%   1-6
server/seedwork/application/__init__.py              0      0   100%
server/seedwork/application/commands.py              5      0   100%
server/seedwork/application/messages.py              7      1    86%   11
server/seedwork/application/modules.py               5      0   100%
server/seedwork/application/queries.py               5      0   100%
server/seedwork/application/types.py                 5      0   100%
server/seedwork/domain/__init__.py                   0      0   100%
server/seedwork/domain/entities.py                   3      0   100%
server/seedwork/domain/repositories.py               6      0   100%
tests/__init__.py                                    0      0   100%
tests/api/__init__.py                                0      0   100%
tests/api/test_auth.py                              29      0   100%
tests/api/test_datasets.py                          25      0   100%
tests/conftest.py                                   38      0   100%
tests/domain/__init__.py                             0      0   100%
tests/domain/test_datasets.py                       21      0   100%
tests/test_app.py                                    7      0   100%
------------------------------------------------------------------------------
TOTAL                                              603     20    97%

Required test coverage of 90% reached. Total coverage: 96.68%

============================== 17 passed in 1.11s ==============================

@florimondmanca florimondmanca added bug Something isn't working tooling labels Jan 17, 2022
@florimondmanca florimondmanca changed the title Fix missing coverage on SQLAlchemy calls Fix coverage detection on SQLAlchemy calls Jan 17, 2022
@florimondmanca
Copy link
Collaborator Author

Je me permets de merge, car le correctif semble assez robuste et peu discutable. @magopian Si question complémentaire, n'hésite pas.

@florimondmanca florimondmanca merged commit 4a392af into master Jan 17, 2022
@florimondmanca florimondmanca deleted the fm/coverage-concurrency-greenlet branch January 17, 2022 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant