I try to make a reusable app which uses transaction.atomic().

When I run my test.py (below) for my reusable app, I get the below errors.

Is it possible to test this reusable app outside of a Django project?

[[[
import unittest
from transaction_utils.transaction import retry


class TestRetry(unittest.TestCase):
    @retry
    def my_func(self):
        return 123

    def test_passthrough(self):
        self.assertEqual(self.my_func(), 123)

if __name__ == '__main__':
    unittest.main()
]]]

[[[
E
======================================================================
ERROR: test_passthrough (__main__.TestRetry)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test.py", line 11, in test_passthrough
    self.assertEqual(self.my_func(), 123)
  File 
"/home/porton/Projects/transaction_utils/transaction_utils/transaction.py", 
line 24, in func_wrapper
    with transaction.atomic():
  File "/usr/lib/python3/dist-packages/django/db/transaction.py", line 152, 
in __enter__
    connection = get_connection(self.using)
  File "/usr/lib/python3/dist-packages/django/db/transaction.py", line 21, 
in get_connection
    return connections[using]
  File "/usr/lib/python3/dist-packages/django/db/utils.py", line 208, in 
__getitem__
    self.ensure_defaults(alias)
  File "/usr/lib/python3/dist-packages/django/db/utils.py", line 176, in 
ensure_defaults
    conn = self.databases[alias]
  File "/usr/lib/python3/dist-packages/django/utils/functional.py", line 
35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/usr/lib/python3/dist-packages/django/db/utils.py", line 156, in 
databases
    self._databases = settings.DATABASES
  File "/usr/lib/python3/dist-packages/django/conf/__init__.py", line 53, 
in __getattr__
    self._setup(name)
  File "/usr/lib/python3/dist-packages/django/conf/__init__.py", line 39, 
in _setup
    % (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting DATABASES, 
but settings are not configured. You must either define the environment 
variable DJANGO_SETTINGS_MODULE or call settings.configure() before 
accessing settings.

----------------------------------------------------------------------
Ran 1 test in 0.001s

FAILED (errors=1)
]]]

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/facd89b9-54de-4f3a-a25a-3195b8c3fb1e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to