-
Notifications
You must be signed in to change notification settings - Fork 182
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
Catch warnings as errors in pytest #283
Conversation
299cc3b
to
a167690
Compare
@jheld @samamorgan I wanted to capture warnings as errors in @samamorgan I noticed that even when the tests fail the CI job does not fail due to piping the output to Side question: What's the purpose of running |
On the migrations, I think that just means it's time to squash the migrations. That should get rid of the warning. Pre-commit should always run as part of CI. A user can easily turn off pre-commit and commit code that does not follow linting rules. CI is the last defense against that. I don't think it should run separately, as that would increase test time since the test environment would have to be regenerated. I'm pretty sensitive to that sort of thing since increased CI time = increased cost in a private repo. |
How does
I agree with you that
I am assuming this is in relation to my question about |
https://docs.djangoproject.com/en/5.0/topics/migrations/#migration-squashing What I believe will happen: For those who have already installed this package and run migrations, the new migration will co-exist and do nothing. For those who are installing this the first time, the squashed migration will be chosen. I think the same PR can both squash the migrations and delete the old ones. Any complexity this represents on behalf of external users of this module will have to be dealt with by those users. This is a normal, expected operation for Django. We may see users come in submitting issues that have themselves in some sort of pickle, and we can just guide them appropriately if that happens, though I suspect even that is unlikely. I trust Django's migration process.
Ahh, I see what you mean. I added |
I think this may be a mistake. Tests are supposed to catch errors. A deprecation warning isn't an error, just a warning of some sort of potential future consequence. Deprecations should be handled on a case-by-case basis, and we don't want tests failing for reasons that aren't actually failures. This reduces the value of tests:
All that is to say, a PR should only be merged if tests pass. That should be a hard line. I would hate to see a situation where a PR is accepted with failing tests. |
You raise some good points. The problem that treating warnings as errors solves is that otherwise these warnings are never visible anywhere and therefore will be missed. A lot of the warnings from this package I found out about because of treating them as errors in our project which subsequently made me do the corresponding PR here to address them. Unless there is another way I don't know about that can make them visible without causing the problems that you outline. However, these errors should only appear if we add support for a new version of Python and/or Django which would be in its own PR. |
@mschoettle I think I've been swayed. One scenario where this would be pretty valuable: Say a contributor adds a third-party package that itself raises Django deprecation warnings (my professional project currently has several packages in this condition). We'd immediately catch that as an error, causing tests to fail, and that gives us clear evidence to reject a contribution. |
With #285 being merged I brought this PR up to date and the tests now pass (no more deprecation warnings). |
@@ -61,6 +61,8 @@ jobs: | |||
run: poetry run pre-commit run --all-files | |||
|
|||
- name: Run Tests (Django ${{ steps.poetry-install.outputs.django_version }}) | |||
# enforce failing fast: https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#exit-codes-and-error-action-preference | |||
shell: bash |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great catch! Just caught this myself on another project (pytest failing to initialize actually caused the job to technically succeed!)
@jheld Please review |
Can you rebase first? |
8814746
to
cfdb924
Compare
@jheld Done. I also had to update the poetry lock file (it was out of date). I left that as a separate commit. |
Make
pytest
treat warnings as errors to catch problems as early as possible. For example, Django deprecation warnings. This should help in keeping up with compatibility for future Django versions.