Re: Testing a reusable app which uses a database
Well, I did it. On Monday, October 3, 2016 at 10:41:59 PM UTC+3, Victor Porton wrote: > > 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/287b442f-6a59-44d8-a0c6-414b90416c59%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Testing a reusable app which uses a database
On 10/03/2016 01:41 PM, Victor Porton wrote: > 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? It is not possible to test it without setting up Django, no. But you don't need a full-fledged "project" for this, the bare minimum you need to do is import django from django.conf import settings settings.configure() # if you need any settings, pass as a dict django.setup() before running your tests. Carl -- 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/0c2f6add-3aab-cb11-981e-3147e203a12a%40oddbird.net. For more options, visit https://groups.google.com/d/optout. signature.asc Description: OpenPGP digital signature
Testing a reusable app which uses a database
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.