Skip to content

Commit

Permalink
💚 [#2762] -- disable requests logging in tests/CI
Browse files Browse the repository at this point in the history
  • Loading branch information
sergei-maertens committed Jun 9, 2023
1 parent b06511f commit 853577d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
26 changes: 26 additions & 0 deletions docs/developers/backend/tests.rst
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,29 @@ Example custom command:
NO_E2E_HEADLESS=1 E2E_DRIVER=firefox python src/manage.py test src --tag=e2e
.. note:: Only the presence of the ``NO_E2E_HEADLESS`` is checked, not the value

Known issues
============

**AssertionError: Database queries to 'default' are not allowed in SimpleTestCase subclasses.**

These are often caused by django-solo ``SingletonModel`` sucblasses that are being
called somewhere, e.g. ``GlobalConfiguration.get_solo``. Sometimes they fetch from
cache, sometimes there is a cache miss and a database query is needed (e.g. when running
tests in reverse).

This is typically a test-isolation smell and the root cause should be fixed. This may
also be caused indirectly if you have ``LOG_REQUESTS`` set to ``True`` in your local
``.env``, as it also results in a django-solo lookup.

The preferred approach to mitigate these kind of issues is to mock the ``get_solo`` call
to prevent cache or DB hits:

.. code-block:: python
@unittest.mock.patch(
"path.to.module.using_the_model.GlobalConfiguration.get_solo",
return_value=GlobalConfiguration(...),
)
def test_something(self, mock_get_solo):
...
6 changes: 6 additions & 0 deletions src/openforms/conf/ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@

os.environ.setdefault("IS_HTTPS", "no")
os.environ.setdefault("SECRET_KEY", "dummy")
# Do not log requests in CI/tests:
#
# * overhead making tests slower
# * it conflicts with SimpleTestCase in some cases when the run-time configuration is
# looked up from the django-solo model
os.environ.setdefault("LOG_REQUESTS", "no")

from .base import * # noqa isort:skip

Expand Down
3 changes: 3 additions & 0 deletions src/openforms/conf/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
)
os.environ.setdefault("RELEASE", "dev")
os.environ.setdefault("SDK_RELEASE", "latest")
# otherwise the test suite is flaky due to logging config lookups to the DB in
# non-DB test cases
os.environ.setdefault("LOG_REQUESTS", "no")

from .base import * # noqa isort:skip

Expand Down

0 comments on commit 853577d

Please sign in to comment.