-
-
Notifications
You must be signed in to change notification settings - Fork 54
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
[Feature Request] @beartype + Django = *a whole lotta nuthin'* #322
Comments
There is a workaround to make Beartype work with pytest and Django by making a wrapper script for pytest e.g. in this fashion:
#!/usr/bin/env python
"""Pytest wrapper which instruments it with Beartype's type annotation checks.
Why is this needed?
------------------
Because if you run pytest with the pytest-beartype plugin with command:
`pytest --beartype-packages='src'`
it will emit the following type warning:
BeartypePytestWarning: Previously imported packages "..." not checkable by beartype.
This is because the Beartype plugin is not able to instrument the packages
that are already imported somehow by pytest.
Refs:
- https://github.com/beartype/beartype/issues/322
- https://github.com/beartype/pytest-beartype/issues/3
So this wrapper script provides the workaround for this issue.
"""
import pytest
from beartype import BeartypeConf
from beartype.claw import beartype_package
type_check_instrumented_packages: list[str] = ["src"] # add here the packages
for package in type_check_instrumented_packages:
beartype_package(package_name=package, conf=BeartypeConf())
# Running pytest tests:
pytest.main() Then you would run it like: ./pytest-with-beartype.py Seems that also the pytest CLI arguments and switches work with this wrapper script so it seems to provide pretty much all that is needed working with pytest. For example: ./pytest-with-beartype.py --cov src |
Ho, ho, ho. Thanks so much for the miracle cure, @jhassine. Finland delivers yet again. Indeed, that's an excellent workaround for this long-standing issue. But... why, Django!? Why do you make @beartype look bad? It's mystifying, honestly. The Here's What We Goin' Do, HomiesLet's at least document @jhassine's clever kludge with:
Thanks again, @jhassine. Since I am lazy, this may not happen for a few |
@leycec I was actually surprised as well why Django stuff was loaded prior to the pytest-beartype plugin. I am now suspecting it might be caused by another pytest plugin which Django pytesters like me might use - |
Exactly! Exactly my thoughts. I didn't even know Is there any way for
Wait. I Just Found a Super-Relevant Upstream Pytest Issue......but everybody's gonna hate it. To quote @pytest dev @RonnyPfannschmidt:
😆 |
i recommend a more nuanced approach to mentioning people, a) the org on github for pytest is |
...ok. Pinging with the I didn't even expect or desire a response, honestly. You're stretched. That's cool. No worries. I'm stretched, too. We're all stretched. I like being stretched, because this bad back ain't gonna stretch itself. That was a bad joke, people – yet a joke nonetheless. 😮💨 There's no expectation of a resolution here. We're all just chillin' in the comfy @beartype space. Please unsubscribe to avoid further comment churn that you will undoubtedly hate. Please accept my apologies, too. Nobody meant to make bad feels! |
Boss-tier @harvymudd ML guru @sunildkumar (Sunil Kumar) reports over at @beartype's sister
pytest-beartype
project that @beartype import hooks silently reduce to noops in Django-driven web apps:Django probably imports Django apps in a non-standard manner circumventing Python's standard
importlib
machinery... probably. In short, we have utterly no idea what is happening here. We only know that Django hates @beartype and that my face hurts. 😮💨The text was updated successfully, but these errors were encountered: