Hello all,
I'm a first time user of py.tests.
My setup is:
* py.test v0.9.0
* Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit
(Intel)] on win32
* Microsoft Windows XP Pro (service pack 2)
The attached file (py-test-generator-trial.py) demonstrates a behavior I
do not understand.
When test_filters() is implemented as a generator, the tests appear to
be run twice and all tests fail during the second iteration except for
the final case ('AL12_1','Gray') in the loop.
When the yield statement, in test_filters(), is disabled and the
assertion statement is enabled, the behavior is as expected -- namely
the tests are performed once and all pass.
Could someone help me to understand this behavior?
Thanks,
--jv
P.S.
I could provide captured output if that is helpful.
'''
unexplained behavior: py.test generative test appears to repeat tests
USE:
> py.test test_PNG_colorization
NOTES:
o Requires installation of py.test (http://codespeak.net/py/dist/test.html)
AUTHOR:
[EMAIL PROTECTED]
'''
from __future__ import absolute_import
class Image(object):
_palettes_ = {
'Flame' : ['OPEN'], # no filter
'Green' : ['PTHK_0'],
'Blue' : ['BE12A_0'],
'Gray' : ['AL12_1'],
}
def __init__(self):
self.info = dict()
def __str__(self):
return self.__class__.__name__
source = Image()
def process(source):
filter = source.info['wavelnth']
processed = Image()
processed.info = source.info
for palette, filters in Image._palettes_.items():
if filter in filters:
processed.info['palette'] = palette
break
else:
raise NotImplementedError('no palette defined for the %s filter' % filter)
return processed
def test_filters():
for filter, palette in zip(('OPEN','PTHK_0','BE12A_0','AL12_1'),
('Flame','Green','Blue','Gray')):
source.info['wavelnth'] = filter
processed = process(source)
print 'yielding:',check,processed,palette
yield check, processed, palette
# NOTE: this does not work as expected
#~ assert processed.info['palette'] == palette, processed.info['palette']
# NOTE: this works as expected!
def check(image,palette):
print 'checking %s palette' % image
assert image.info['palette'] == palette, image.info['palette']
_______________________________________________
py-dev mailing list
py-dev@codespeak.net
http://codespeak.net/mailman/listinfo/py-dev