splitting tests.py

14 views
Skip to first unread message

gderazon

unread,
Jan 23, 2009, 9:10:16 AM1/23/09
to Django users
My tests.py has become too big, I want to split it to several test
files and still be able to run the tests with manage.py tests ...
How can I do that?
I'm working with django 1.0 stable release.

Raffaele Salmaso

unread,
Jan 23, 2009, 9:27:20 AM1/23/09
to django...@googlegroups.com
tests/
+- __init__.py
+- test1.py
+- test2.py
\- test3.py

--
()_() | That said, I didn't actually _test_ my patch. | +----
(o.o) | That's what users are for! | +---+
'm m' | (Linus Torvalds) | O |
(___) | raffaele at salmaso punto org |

gderazon

unread,
Jan 23, 2009, 10:23:34 AM1/23/09
to Django users
Thanks Raffaele,
I tried it, and it seems to ignore the tests files.
(I get "Ran 0 tests in 0.000s")
Is there anything that I should write in the __init__.py file?

On Jan 23, 4:27 pm, Raffaele Salmaso <raffaele.salm...@gmail.com>
wrote:

Raffaele Salmaso

unread,
Jan 23, 2009, 10:42:28 AM1/23/09
to django...@googlegroups.com
gderazon wrote:
>> tests/
>> +- __init__.py
>> +- test1.py
>> +- test2.py
>> \- test3.py

if you are using unittest in __init__.py:

from test1.py import *
from test2.py import *
from test3.py import *

if you are using doctest in __init__.py:

from test1 import MY_TEST1
from test2 import MY_TEST2
from test3 import MY_TEST3

__test__ = {
'test1' : MY_TEST1,
'test2' : MY_TEST2,
'test3' : MY_TEST3,
}

docs:
http://docs.djangoproject.com/en/dev/topics/testing/
http://docs.python.org/library/unittest.html
http://docs.python.org/library/doctest.html

gderazon

unread,
Jan 23, 2009, 10:45:46 AM1/23/09
to Django users
Thanks! it works!

On Jan 23, 5:42 pm, Raffaele Salmaso <raffaele.salm...@gmail.com>
wrote:
> gderazon wrote:
> >> tests/
> >> +- __init__.py
> >> +- test1.py
> >> +- test2.py
> >> \- test3.py
>
> if you are using unittest in __init__.py:
>
> from test1.py import *
> from test2.py import *
> from test3.py import *
>
> if you are using doctest in __init__.py:
>
> from test1 import MY_TEST1
> from test2 import MY_TEST2
> from test3 import MY_TEST3
>
> __test__ = {
>   'test1' : MY_TEST1,
>   'test2' : MY_TEST2,
>   'test3' : MY_TEST3,
>
> }
>
> docs:http://docs.djangoproject.com/en/dev/topics/testing/http://docs.python.org/library/unittest.htmlhttp://docs.python.org/library/doctest.html
Reply all
Reply to author
Forward
0 new messages