adamchainz / django-rich

Extensions for using Rich with Django.
MIT License
121 stars 10 forks source link

Fix failing tests if the TERM variable is set to unknown #103

Closed ogayot closed 1 year ago

ogayot commented 1 year ago

When running the test-suite with TERM=unknown, the tests fail because the generated output is not "rich".

This happens because python rich will disable color and style if the TERM variable is set to either unknown or dumb [1]

This patch monkey-patches the environment to make the test suite insensitive to the TERM variable.

[1] https://rich.readthedocs.io/en/stable/console.html?highlight=unknown#environment-variables

Signed-off-by: Olivier Gayot olivier.gayot@canonical.com

adamchainz commented 1 year ago
  1. Seems like FORCE_COLOR is preferable, as the docs note it's for CI
  2. We want this for the whole test suite, not just one test class, so best done in a pytest fixture in conftest.py.

I will update.

adamchainz commented 1 year ago

Okay turns out we can't use FORCE_COLOR because we test the force colro functionality, and setting the TERM env var around the whole test process or test disables pytest's colouring. Switched to localized overrides.

ogayot commented 1 year ago

Thanks @adamchainz !