Re: Want to have unit tests in multiple files

2008-05-23 Thread Sebastian Noack
On Fri, 23 May 2008 13:32:45 -0500
"Gary Wilson Jr." <[EMAIL PROTECTED]> wrote:
> In case you haven't figured this out already, it can be done by 
> importing your unit test classes from the test/*.py modules in 
> tests/__init__.py

That is exactly what I have done at my work, just a few days ago. I
put the code below into the tests/__init__.py. You can use it as is.

def get_test_modules():
from os import path, listdir

names = set()
for f in listdir(path.dirname(__file__)):
if f.startswith('.') or f.startswith('__'):
continue
names.add(f.split('.')[0])

for name in names:
yield (name, __import__('%s.%s' % (__name__, name), {}, {}, ['']))

def setup_doc_tests():
for name, module in get_test_modules():
# Try to find an API test in the current module, if it fails continue.
try:
api_tests = module.__test__['API_TESTS']
except (AttributeError, TypeError, KeyError):
continue

# Import possible dependecies of the API test from the current module.
for k, v in module.__dict__.iteritems():
if k.startswith('__'):
continue
globals()[k] = v

# Attach the API test to the __test__ dictionary if it exists or create 
it.
try:
globals()['__test__'][name] = api_tests
except KeyError:
globals()['__test__'] = {name: api_tests}

def setup_unit_tests():
import unittest

for name, module in get_test_modules():
# Import each TestCase from the current module.
for k, v in module.__dict__.iteritems():
if not (isinstance(v, type) and issubclass(v, unittest.TestCase)):
continue
globals()[k] = v

setup_doc_tests()
setup_unit_tests()


signature.asc
Description: PGP signature


Re: Want to have unit tests in multiple files

2008-05-23 Thread Gary Wilson Jr.

Alex Koshelev wrote:
> No. Not `tests.py`, but `tests` module - that can be a package of many
> other modules/files

In case you haven't figured this out already, it can be done by 
importing your unit test classes from the test/*.py modules in 
tests/__init__.py

Gary

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en
-~--~~~~--~~--~--~---



Re: Want to have unit tests in multiple files

2008-05-06 Thread Alex Koshelev

No. Not `tests.py`, but `tests` module - that can be a package of many
other modules/files

On May 7, 12:21 am, Steve <[EMAIL PROTECTED]> wrote:
> Hi, we're just getting started using Django unit tests, and it looks
> like the documentation says you can only have unit tests in two files:
> models.py and tests.py.  We would prefer to put our unit tests in many
> different files, with, say, each main-line .py file having a
> corresponding unit-test file.  Is there a convenient way to do this in
> Django?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en
-~--~~~~--~~--~--~---



Re: Want to have unit tests in multiple files

2008-05-06 Thread Honza Král
Hi,
you can always define your own test runner which will look not only in
tests and models, but in every module.

This question is more suited for the django-users mailing list, this
list is intended for discussing development of django internals.

On Tue, May 6, 2008 at 10:21 PM, Steve <[EMAIL PROTECTED]> wrote:
>
>  Hi, we're just getting started using Django unit tests, and it looks
>  like the documentation says you can only have unit tests in two files:
>  models.py and tests.py.  We would prefer to put our unit tests in many
>  different files, with, say, each main-line .py file having a
>  corresponding unit-test file.  Is there a convenient way to do this in
>  Django?
>  >
>



-- 
Honza Král
E-Mail: [EMAIL PROTECTED]
ICQ#: 107471613
Phone: +420 606 678585

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en
-~--~~~~--~~--~--~---