[Zope3-Users] Add unittest

Andrew Groom andrew at reurbanise.co.nz
Tue Apr 17 18:30:30 EDT 2007


Hi Florian,

I've had some success with:

import unittest

class MyTestClass (unittest.TestCase):
	def test_something (self):
		...

def test_suite ():
     return unittest.TestLoader().loadTestsFromTestCase(MyTestClass)

if __name__ == '__main__':
     unittest.main(defaultTest='test_suite')

Florian Lindner wrote:
> Hello,
> I've tried to add a test to my package (I must confess it's my first test.)
> 
> I've added an directory "tests", created an empty __init__.py in it and a file 
> named test_proxycache.py which contains:
> 
> import unittest
> from zope.testing.doctestunit import DocTestSuite
>  
> from zope.app.container.tests.test_icontainer import TestSampleContainer
> 
> from ProxyCache.proxycache import ProxyCache
>  
> class Test(TestSampleContainer):
>     def makeTestObject(self):
>         return ProxyCache()
>      
> def test_suite():
>     return unittest.TestSuite((
>         DocTestSuite("ProxyCache.proxycache"),
>         unittest.makeSuite(Test) ))
>             
>             
> if __name__ == "__main__":
>      unittest.main(defaultTest="test_suite")
> 
> as a first step.
> 
> Now I try to run the tests:
> 
> florian at horus ~/Zope3 $ python 
> test.py -vpu --dir ../Desktop/zope/lib/python/ProxyCache/
> Running tests at level 1
> Traceback (most recent call last):
>   File "test.py", line 61, in ?
>     result = testrunner.run(defaults)
>   File "/home/florian/Zope3/src/zope/testing/testrunner.py", line 256, in run
>     failed = not run_with_options(options)
>   File "/home/florian/Zope3/src/zope/testing/testrunner.py", line 365, in 
> run_with_options
>     tests_by_layer_name = find_tests(options, found_suites)
>   File "/home/florian/Zope3/src/zope/testing/testrunner.py", line 1033, in 
> find_tests
>     for suite in found_suites:
>   File "/home/florian/Zope3/src/zope/testing/testrunner.py", line 1072, in 
> find_suites
>     for fpath, package in find_test_files(options):
>   File "/home/florian/Zope3/src/zope/testing/testrunner.py", line 1138, in 
> find_test_files
>     for f, package in find_test_files_(options):
>   File "/home/florian/Zope3/src/zope/testing/testrunner.py", line 1166, in 
> find_test_files_
>     for (p, package) in test_dirs(options, {}):
>   File "/home/florian/Zope3/src/zope/testing/testrunner.py", line 1220, in 
> test_dirs
>     p = import_name(p)
>   File "/home/florian/Zope3/src/zope/testing/testrunner.py", line 1236, in 
> import_name
>     __import__(name)
> ValueError: Empty module name
> 
> 
> tried also some variations but the error does not change.
> 
> What's wrong there?
> 
> Thanks,
> 
> Florian
> _______________________________________________
> Zope3-users mailing list
> Zope3-users at zope.org
> http://mail.zope.org/mailman/listinfo/zope3-users

-- 
-----------------------------------
Reurbanise - Urban Sustainability
ph: (03) 3528 055, mobile: 0274 992 569
http://www.reurbanise.co.nz


More information about the Zope3-users mailing list