vendredi 24 février 2017

Incorporating Django's system checks into unit test suite?

I recently deployed some broken code to our staging environment. The new code failed Django's system checks (error messages reproduced below, though this question is more general). Our unit test suite ran cleanly. My question is this: what is the right way to ensure that system checks get run before code can be deployed?

Initially I guessed that the tests were able to run without performing system checks because we use pytest instead of Django's test runner. However, adding a simple test and invoking manage.py test showed that the Django test runner also runs without performing system checks.

One idea I had is to run the manage.py check command in our build pipeline, and fail the build on a nonzero return value. A downside of this approach is that it'd introduce another developer step before code could be committed (e.g. remember to run manage.py check in addition to running the unit test suite).

Another idea is to add a unit test that runs the system checks. This seems technically feasible, but is it consistent with the purpose and design of Django's system check framework?

I note that the documentation has a section on writing tests for custom checks, which doesn't quite get at what I'm asking. I don't see other documentation on incorporating system checks into tests in the Django docs.

Error messages:

SystemCheckError: System check identified some issues:

ERRORS:
myapp.MyCoolModel.linked_groups: (fields.E304) Reverse accessor for 'MyCoolModel.linked_groups' clashes with reverse accessor for 'MyCoolModel.primary_group'.
    HINT: Add or change a related_name argument to the definition for 'MyCoolModel.linked_groups' or 'MyCoolModel.primary_group'.
myapp.MyCoolModel.primary_group: (fields.E304) Reverse accessor for 'MyCoolModel.primary_group' clashes with reverse accessor for 'MyCoolModel.linked_groups'.
    HINT: Add or change a related_name argument to the definition for 'MyCoolModel.primary_group' or 'MyCoolModel.linked_groups'.

Aucun commentaire:

Enregistrer un commentaire