Open evansd opened 11 months ago
This works for me:
$ pytest --cov=ehrql.utils.functools_utils tests/unit/utils/test_functools_utils.py
============================= test session starts ==============================
platform linux -- Python 3.11.2, pytest-7.4.2, pluggy-1.0.0
rootdir: /home/inglesp/work/ebmdatalab/ehrql
configfile: pyproject.toml
plugins: xdist-3.3.1, cov-4.1.0, hypothesis-6.87.3, mock-3.11.1
collected 5 items
tests/unit/utils/test_functools_utils.py ..... [100%]
------------------------------ coverage ------------------------------
Name Stmts Miss Branch BrPart Cover
-----------------------------------------
TOTAL 20 0 2 0 100%
1 file skipped due to complete coverage.
Required test coverage of 100.0% reached. Total coverage: 100.00%
============================== 5 passed in 0.09s ===============================
@evansd can we close?
I still get the same error, though it's useful information that you don't.
I now get this error as well.
And now I don't!
Aha! It depends on whether you've got a local editable install of ehrql...
Right, this one's fun.
The problem's only indirectly related to Trino, and the exception is actually caused by a nasty interaction between the following:
See inglesp/pytest-warnings-coverage-sqlalchemy for a minimal example of the problem.
The problem was introduced to this repo when we started filtering a deprecation warning from SQLAlchemy here.
Instead of filtering the warning, we can address it quite easily: a job for tomorrow.
It used to be possible to check the coverage of a specific module by a specific set of tests using something like:
However now doing so results in this cryptic error:
For some reason, Coverage ends up importing modules twice and this is causing some kind of SQLAlchemy registration hook to fire a second time and then to error.
Using git-bisect I tracked it down to this commit which suggests that the Trino SQLAlchemy connector is at fault. I also note we needed to silence a deprecation warning here, so that might be related.
The trino-python-client project looks reasonably active so hopeful they'd accept a patch to fix this. (I think it's unlikely they'd diagnose and fix it for us on the basis of a bug report as I can't see it being a huge priority for them.)