python - Django - Defining a child class inside a TestCase -


i packaging django app reuse (and can used others), , create test case mimics defining child class when app used in different contexts.

i found this solution similar in python test case, however, getting following error django test case.

runtimeerror: model class tests.test_unit_health.heart doesn't declare explicit app_label , isn't in application in installed_apps. 

below similar have setup generating error:

models.py

from django.db import models   class healthtest(models.model):     # attributes...     # methods...     def get_score(self, **kwargs):         score = self.score(**kwargs)         # more logic 

test_unit_health.py

from django.test import testcase health.models import healthtest   class healthtestcase(testcase):     def setup(self):         class heart(healthtest):             def score(self, heartrate):                 if heartrate > 90:                     return 2                 else:                     return 1 

the full error looks this:

====================================================================== error: tests.test_unit_health (unittest.loader.moduleimportfailure) ---------------------------------------------------------------------- importerror: failed import test module: tests.test_unit_health traceback (most recent call last):   file "/system/library/frameworks/python.framework/versions/2.7/lib/python2.7/unittest/loader.py", line 254, in _find_tests     module = self._get_module_from_name(name)   file "/system/library/frameworks/python.framework/versions/2.7/lib/python2.7/unittest/loader.py", line 232, in _get_module_from_name     __import__(name)   file ".../test_unit_health.py", line 8, in <module>     class heart(healthtest):   file ".../env/lib/python2.7/site-packages/django/db/models/base.py", line 118, in __new__     "installed_apps." % (module, name) runtimeerror: model class tests.test_unit_health.heart doesn't declare explicit app_label , isn't in application in installed_apps. 

any getting work appreciated. thank you!

https://docs.djangoproject.com/en/1.10/internals/contributing/writing-code/unit-tests/#isolating-model-registration - 1 think. ps have @ https://docs.djangoproject.com/en/1.10/ref/models/options/#app-label


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -