Open n1ngu opened 2 years ago
The tests can be reduced so something like
from django.core.management import call_command
def test_migrations(db):
call_command("makemigrations", "--check", "--dry-run")
def test_check(db):
call_command("check", "--fail-level", "WARNING")
I am somewhat bored of copypasting this in every project
AFAIU, pytest collection hooks could be used to extend the users test suite with this two unit tests.
https://docs.pytest.org/en/latest/reference/reference.html#collection-hooks
I personally don't think a library should be handling this. While it's certainly common and good to do this, the library shouldn't necessarily be implementing this for the user.
That being said, here's my version of these tests that I think are a bit more explicit than what you've shown.
import pytest
from django.core import management
@pytest.mark.django_db
def test_no_migrations(capsys: pytest.CaptureFixture):
management.call_command("makemigrations", dry_run=True)
captured: str = capsys.readouterr().out
assert "No changes detected" in captured
def test_no_issues(capsys: pytest.CaptureFixture):
management.call_command("check", fail_level="WARNING")
captured: str = capsys.readouterr().out
assert "System check identified no issues" in captured
As part of my test scripts I'll usually run
django-admin check
anddjango-admin makemigrations --check --dry-run
to assert nobody missed something.Am I missing a way to hook those administrative commands with this library? Wouldn't it be interesting to have some kind of cli flag or fixture to trigger them during a pytest run?