[TIP] Guidelines for where to put tests & how to package them

Michael Foord fuzzyman at voidspace.org.uk
Mon Mar 1 05:37:19 PST 2010


On 01/03/2010 13:32, Olemis Lang wrote:
> On Sat, Feb 27, 2010 at 2:33 PM, Michael Foord
> <fuzzyman at voidspace.org.uk>  wrote:
>    
>> On 27/02/2010 19:22, C. Titus Brown wrote:
>>
>>      
> [...]
>    
>> Olemis was confused as to what setuptools did - it does not support a
>> callable for the test_suite argument.
>>
>>      
> I was terribly wrong about `suite` and `unittest`, yes, however if
> there's something wrong with the following snippet
>    

According to the setuptools documentation the test_suite argument *can* 
be a callable. So you were right about that and Phillip was wrong!

With the new unittest you could support both by adding a load_tests 
function in *addition* to your test_suite function:

def load_tests(loader, tests, pattern):
return test_suite()

So I'm still not convinced I need to support the 'test_suite as 
callable' protocol. However this discussion has uncovered a lot of 
issues and 'we' (including Tarek) need to work out how this will work in 
distutils2 and whether we can up with conventions that meet Titus' use 
cases as well.

All the best,

Michael

> {{{
> #!sh
>
> $ cat setup.py
>
> from setuptools import setup
>
> setup(name='xxx', version='1.0', description='Xxx', package_dir={'xxx'
> : ''}, py_modules=['xxx.py'], test_suite='xxx.my_suite')
>
> $ cat xxx.py
>
> def my_suite():
>    from unittest import TestCase as TC, TestSuite as TS
>    class MyTC(TC):
>      def test_fail(self):
>        self.fail()
>    s = TS()
>    s.addTest(MyTC('test_fail'))
>    return s
>
> $ python setup.py test
> running test
> running egg_info
> writing xxx.egg-info/PKG-INFO
> writing top-level names to xxx.egg-info/top_level.txt
> writing dependency_links to xxx.egg-info/dependency_links.txt
> package init file '__init__.py' not found (or not a regular file)
> file py.py (for module xxx.py) not found
> reading manifest file 'xxx.egg-info/SOURCES.txt'
> writing manifest file 'xxx.egg-info/SOURCES.txt'
> running build_ext
> test_fail (xxx.MyTC) ... FAIL
>
> ======================================================================
> FAIL: test_fail (xxx.MyTC)
> ----------------------------------------------------------------------
> Traceback (most recent call last):
>    File "/.../temp/xxx.py", line 6, in test_fail
>      self.fail()
> AssertionError
>
> ----------------------------------------------------------------------
> Ran 1 test in 0.001s
>
> FAILED (failures=1)
> }}}
>
> ... then I'm also terribly wrong about setuptool's `test_suite` too ...
>
> CMIIW
>
>    


-- 
http://www.ironpythoninaction.com/
http://www.voidspace.org.uk/blog

READ CAREFULLY. By accepting and reading this email you agree, on behalf of your employer, to release me from all obligations and waivers arising from any and all NON-NEGOTIATED agreements, licenses, terms-of-service, shrinkwrap, clickwrap, browsewrap, confidentiality, non-disclosure, non-compete and acceptable use policies (”BOGUS AGREEMENTS”) that I have entered into with your employer, its partners, licensors, agents and assigns, in perpetuity, without prejudice to my ongoing rights and privileges. You further represent that you have the authority to release me from any BOGUS AGREEMENTS on behalf of your employer.





More information about the testing-in-python mailing list