diff --git a/InvenTree/InvenTree/apps.py b/InvenTree/InvenTree/apps.py index a290811b97..a6116f0ec2 100644 --- a/InvenTree/InvenTree/apps.py +++ b/InvenTree/InvenTree/apps.py @@ -31,7 +31,7 @@ class InvenTreeConfig(AppConfig): if not isInTestMode(): self.update_exchange_rates() - if canAppAccessDatabase() or settings.TESTING: + if canAppAccessDatabase() or settings.TESTING_ENV: self.add_user_on_startup() def remove_obsolete_tasks(self): @@ -192,7 +192,7 @@ class InvenTreeConfig(AppConfig): logger.info(f'User {str(new_user)} was created!') except IntegrityError as _e: logger.warning(f'The user "{add_user}" could not be created due to the following error:\n{str(_e)}') - if settings.TESTING: + if settings.TESTING_ENV: raise _e # do not try again diff --git a/InvenTree/InvenTree/settings.py b/InvenTree/InvenTree/settings.py index c45be06f4b..7291178e4a 100644 --- a/InvenTree/InvenTree/settings.py +++ b/InvenTree/InvenTree/settings.py @@ -37,6 +37,7 @@ def _is_true(x): # Determine if we are running in "test" mode e.g. "manage.py test" TESTING = 'test' in sys.argv +TESTING_ENV = False # New requirement for django 3.2+ DEFAULT_AUTO_FIELD = 'django.db.models.AutoField' diff --git a/InvenTree/InvenTree/tests.py b/InvenTree/InvenTree/tests.py index e9d40f5297..9014ee1591 100644 --- a/InvenTree/InvenTree/tests.py +++ b/InvenTree/InvenTree/tests.py @@ -432,6 +432,8 @@ class TestSettings(TestCase): def test_set_user_to_few(self): # add shortcut user_count = self.user_mdl.objects.count + # enable testing mode + settings.TESTING_ENV = True # nothing set self.assertEqual(user_count(), 0) @@ -455,3 +457,6 @@ class TestSettings(TestCase): with self.assertRaises(IntegrationPluginError): self.run_reload() self.assertEqual(user_count(), 1) + + # make sure to clean up + settings.TESTING_ENV = False