Re: [py-dev] py.test generative tests unexpected behavior
----- Original Message ----- From: Carl Friedrich Bolz <cfbolz@gmx.de> Date: Monday, December 17, 2007 8:25 am Subject: Re: [py-dev] py.test generative tests unexpected behavior
Hi!
j. vickroy wrote: [snip]
The attached file (py-test-generator-trial.py) demonstrates a behavior I do not understand. [snip]
I don't know generative test semantics all that well, I hoped somebody else would answer this. However, my theory is as follows:
py.test first collects all the results of the generator and then runs them all. Since your test keeps global state, the state is already changed when the first test is run. To me this sounds like reasonable behavior, global state is not good in tests anyway.
Does that make things clearer?
Cheers,
Carl Friedrich _______________________________________________ py-dev mailing list py-dev@codespeak.net http://codespeak.net/mailman/listinfo/py-dev
Thanks, Carl. I do understand (at least) some of the pitfalls of global state and I do *almost always* avoid using it. However, in this case, I am having difficulty seeing why it is responsible for the observed behavior. Having said that, prior to using the global *image* object, I tried to use the setup_module(module) function to define the *image* object but was unable to determine how to reference it in the test function. The global *image* object was a crude work-around. Can you offer some suggestions on how I should have proceeded given that I really do not need to create a new *image* object for each test. Thanks again, -- jv
Jim.Vickroy@noaa.gov wrote:
----- Original Message ----- From: Carl Friedrich Bolz <cfbolz@gmx.de> Date: Monday, December 17, 2007 8:25 am Subject: Re: [py-dev] py.test generative tests unexpected behavior
Hi!
j. vickroy wrote: [snip]
The attached file (py-test-generator-trial.py) demonstrates a behavior I do not understand. [snip]
I don't know generative test semantics all that well, I hoped somebody else would answer this. However, my theory is as follows:
py.test first collects all the results of the generator and then runs them all. Since your test keeps global state, the state is already changed when the first test is run. To me this sounds like reasonable behavior, global state is not good in tests anyway.
Does that make things clearer?
Cheers,
Carl Friedrich _______________________________________________ py-dev mailing list py-dev@codespeak.net http://codespeak.net/mailman/listinfo/py-dev
Thanks, Carl.
I do understand (at least) some of the pitfalls of global state and I do *almost always* avoid using it. However, in this case, I am having difficulty seeing why it is responsible for the observed behavior.
I think what py.test does is essentially this: l = list(test_filters()) # at this point source.info['palette'] == 'Gray' # and that won't change any more for t in l: t[0](*t[1:]) # here the check functions are executed
Having said that, prior to using the global *image* object, I tried to use the setup_module(module) function to define the *image* object but was unable to determine how to reference it in the test function.
You can stick the the image into the module argument that the setup_module function receives as first arg: def setup_module(mod): mod.image = ... After the setup, the global name 'image' is bound to ... This wouldn't have solved your problem, though, since it is still global state. [snip] Cheers, Carl Friedrich
participants (2)
-
Carl Friedrich Bolz -
Jim.Vickroy@noaa.gov