Unit testing a unittest custom test runner in Django

I am trying to unit test a custom test runner using unittest framework but I get this error.

  File "/usr/local/lib/python3.7/dist-packages/django/test/runner.py", line 466, in setup_test_environment
    setup_test_environment(debug=self.debug_mode)
  File "/usr/local/lib/python3.7/dist-packages/django/test/utils.py", line 111, in setup_test_environment
    "setup_test_environment() was already called and can't be called "
RuntimeError: setup_test_environment() was already called and can't be called again without first calling teardown_test_environment().

I understand that this error message is pretty self explanatory but the problem with running teardown_test_environment within the unit test ends up in this error message

  File "/usr/local/lib/python3.7/dist-packages/django/test/runner.py", line 588, in teardown_test_environment
    teardown_test_environment()
  File "/usr/local/lib/python3.7/dist-packages/django/test/utils.py", line 144, in teardown_test_environment
    saved_data = _TestState.saved_data
AttributeError: type object '_TestState' has no attribute 'saved_data'

Has anyone encountered something like this before?

Back to Top