-
Notifications
You must be signed in to change notification settings - Fork 347
pytest-django 2.7.0 breaks usage with pytest-cov #175
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
Comments
It seems that fixing this will basically require rolling back a bunch of changes that were made in 2.7 that had the effect of importing and configuring Django eagerly rather than lazily. I'm not sure what the purpose of those changes was - was it just a matter of better error reporting on failure to import settings? I can submit a pull request to go back to lazy configuration of Django, as it seems to me that that is better (and doesn't break pytest-cov), but I would be interested first in knowing what the reasons were for moving to eager configuration. Do you have any input, @pelme ? |
The change to call #119 (comment) describes the reasoning why this is needed: pytest-django won't be able to support Django 1.9 at all unless From my point of view, your suggestion to lazy import during test collection and then call I can see two possible solutions (to solve the original coverage issue):
|
I see. I already limit module-level imports in I'm not a fan of Django 1.7+ trying to control the import order in this way, but I understand the reasons why that was done and the difficulties doing it any other way, given the constraints of Django's design. In theory I would still like to look into the possibility of relaxing these import-order restrictions, but I'm not sanguine about the likelihood of success. I am also not sure that it will be possible to redesign pytest-cov to start coverage so early, but I can look into that too. For my own projects it almost seems simplest to just abandon Last question: I see that in the current code in |
It is certainly a bad situation if I quick observation (I have not tried this yet): The If Regarding the second Thanks for taking the time looking into this, this kind of feedback is very welcome! |
Unfortunately the I wonder if we could lower our aim here a bit and have there be some explicit way to tell pytest-django "I am ok with not being able to do Django imports at module level in my conftest.py files, please don't call |
FWIW, on further reflection I've decided that in fact pytest-django's new behavior is correct, and the fault here really lies with |
...and to compound my embarrassment, it turns out that a new version of pytest-cov has already been released that actually does fix this problem; I just didn't understand well enough how various hooks (including the undocumented So I think there is now no problem here, and this can be closed. Apologies for all the noise :/ |
Thanks a lot for taking the time and effort to dig into this rather involved issue. Your contributions (to Django, testing in Python and other projects) are much appreciated! |
With the upgrade from 2.6.2 to 2.7.0 (on a Django 1.7 project), suddenly a bunch of module-level code is recorded as uncovered by pytest-cov.
I believe this is because
django.setup()
is now called sooner, before pytest-cov has a chance to start coverage measurement. Probably due to 85581fbStill exploring, will suggest a fix once I find one.
The text was updated successfully, but these errors were encountered: