How can I run Django project

This seems like a no-brainer, and I'm hesitant to admit that I've spent about two hours trying to find the answer, but I can't figure out how to run project-level tests for a django project.

Just to be clear, running tests for the apps in the project is no problem. I understand './manage.py test', but it doesn't find the project-level tests that I have written.

I tried putting the project-level tests in 'my-django-project/tests.py' and 'my-django-project/tests/testcode.py' but these tests aren't found. What am I missing?


There's no such thing. Put all your tests in an app.


While there isn't something built into Django, Django-nose finds and runs tests at the project level as well as any subdirectories. Unfortunately, it doesn't find tests for installed apps that aren't placed in a subdirectory of the project directory.

Installation instructions can be found at: http://pypi.python.org/pypi/django-nose/0.1


./manage.py test can be used to execute arbitrary Python code, which means you can make it run project-wide tests if you want. A subclass of DjangoTestSuiteRunner that finds the project-wide tests and executes them as well should do the trick. If those project-wide tests involve models, you probably want to put them within one of the corresponding apps.

https://docs.djangoproject.com/en/dev/topics/testing/advanced/#using-different-testing-frameworks

EDIT: Django 1.6 can discover tests anywhere. https://docs.djangoproject.com/en/dev/releases/1.6/#discovery-of-tests-in-any-test-module

链接地址: http://www.djcxy.com/p/46902.html

上一篇: 为什么SIGINT在这里被抓到?

下一篇: 我如何运行Django项目