문제

So I followed the instructions on the site here:

https://docs.djangoproject.com/en/1.5/topics/testing/overview/

but what confuses me is the portion that describes the scope of tests when running. It says:

By default, this will run every test in every application in INSTALLED_APPS. If you only want to run tests for a particular application, add the application name to the command line.

For example, if your INSTALLED_APPS contains 'myproject.polls' and 'myproject.animals', you can run the myproject.animals unit tests alone with this command:

What confuses me is that the directory structure for the site is laid out like so

myproject/
    manage.py
    mysite/
        __init__.py
        settings.py
        urls.py
        views.py
        models.py
        wsgi.py

So I don't really have any smaller apps. I essentially just have 1 big app which is the site. There are a number of apps that are in my INSTALLED_APPS variable but I just want to run the test on mysite. How would I go about doing that?

Or, would I have to:

Move the entire site to its own app, laying out a directory structure like this and add that app to INSTALLED_APPS

myproject/
    manage.py
    mysite/
        __init__.py
        settings.py
        urls.py
        wsgi.py

    mysiteapp/
        views.py
        models.py

Also, in general would that be a better structure for my django project?

도움이 되었습니까?

해결책

The Django Testing suite basically will test your one big site as is, which I believe is what you want.

Others structure their Django site as an aggregate of smaller apps. Like a sub app for authentication, or one for a particular feature with different requirements, or just having a bunch of components connected together so that you can reuse parts of your past projects.

In those cases, someone might only want to test one of those components and not the whole thing. For example, if you have a working site and you add in an app from a past project and everything breaks, you would want to focus your tests on that app. This is what the warning is about. Meaning that if you only want to test a sub app then you should specify it.

For your case, testing everything works because your using only one app.

HTH

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top