[py-dev] py.test: initializing test environment

Ian Bicking ianb at colorstudy.com
Fri Nov 4 17:15:54 CET 2005


Jan Balster wrote:
> Hi Ian,
> 
> I'm not sure if this code snippet is the solution you wanted but I'll provide it
> anyway :-)
...
> # hooking into py.test Directory collector's chain ...
> class SetupDirectory(py.test.collect.Directory):
> 
>     def __init__(self, fspath, parent=None):
>         super(SetupDirectory, self).__init__(fspath, parent)
>         # create files and dirs
>         if option.setup_tests:
>             setup_tests()
> 
> Directory = SetupDirectory
> ----------------------------------------------------------------

This is actually what I initially tried, though I only overrode .run(), 
not .__init__().  At least with .run() it didn't get invoked when I 
specified an exact file to test.  Does Directory.__init__ always get 
invoked?


-- 
Ian Bicking  /  ianb at colorstudy.com  /  http://blog.ianbicking.org



More information about the Pytest-dev mailing list