开发者

How can I run Django project-level tests?

开发者 https://www.devze.com 2023-01-07 01:34 出处:网络
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.

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-dj开发者_开发问答ango-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

0

精彩评论

暂无评论...
验证码 换一张
取 消