0

I have a project that shares a database among many wsgi apps (sites framework from contrib is in heavy use). Each wsgi app has it's own module in project dir with it's own settings.py that extend global_settings.py in main project dir (each settings file simply imports * from global_settings). Also some sites have their own urls and extra views/templates that cannot be tested globally. All the sites share most apps though. Also due to customisations of views (subclassed cbl views) I need to test each site separately. Django expects tests.py only in app dirs so I can't issue:

./manage.py test first_site --settings=first_site.settings

since first_site is just a python module not a django app. How can I overcome this?

4

2 回答 2

0

我发现了这个: http: //pypi.python.org/pypi/django-discover-runner

安装 django-discover-runner 后(例如在 pip 中):

pip install -U django-discover-runner

您只需在自定义站点设置中添加一行:

TEST_RUNNER = 'discover_runner.DiscoverRunner'

这个命令将从名为的普通 python 模块运行测试first_site

./manage.py test first_site --settings=first_site.settings

似乎是合法的。

于 2012-09-23T18:08:13.153 回答
0

我只是开始多站点测试,现在想出了一个原始的解决方案:

from django.test import override_settings

@override_settings(SITE_ID=1)
def test_multisite_one(self):
    from django.contrib.sites.models import Site
    self.assertEqual(1, Site.objects.get_current().id)
于 2015-03-31T13:19:06.397 回答