9

Is there an easy way to get a list of all tests in a Django project without running the tests themselves? I was hoping for something like ./manage.py test --list.

Hakan B.
  • 2,001
  • 21
  • 28
  • 2
    besides `grep -R "^\w*def test_.*\(.*\)\:$" --include "*.py"`? – Thomas May 03 '13 at 06:57
  • 1
    Running that on OS X 10.8.3 returned `grep: warning: recursive search of stdin` and the process hung indefinitely without returning any results. Modifying the command to `grep -R "def test_" --include "*.py" .` worked for me. Thanks for the clever solution. – Hakan B. May 03 '13 at 07:25

1 Answers1

14

In my opinion, the more correct way is to use the actual tool for running tests. E.g. in case of nose:

./manage.py test <app> --verbosity 2 --collect-only

FYI, py.test also has --collectonly option to print tests instead of executing.

Also see:

Community
  • 1
  • 1
alecxe
  • 414,977
  • 106
  • 935
  • 1,083
  • 4
    Are you sure this works? It sounds good in theory but running your command returns `./manage.py: error: no such option: --collect-only`. I'm using Django 1.4.4 and using Nose as the test runner via django-nose. – Hakan B. May 21 '13 at 00:58
  • Yes, I've used it for a long time before. Have you added `django_nose` to the INSTALLED_APPS and set `TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'`? – alecxe May 21 '13 at 04:55
  • Hm, do you see `nose` command-line options while running `manage.py` with `--help`? – alecxe May 21 '13 at 09:04
  • I don't see `nose` options when running either `manage.py --help` or `mange.py test --help`, unfortunately. It's strange because I can see my tests are definitely being run via `nose`. I tried reinstalling `django-nose` but no luck. It must be something on my end. Thanks for your help. – Hakan B. May 21 '13 at 20:23
  • 2
    You are welcome. Please try to move `django_nose` to the end of `INSTALLED_APPS`. – alecxe May 21 '13 at 20:26
  • That did it, thanks! I now see the `nose` command-line options and your original answer to the question works as well. – Hakan B. May 21 '13 at 20:31