[Avocado-devel] initializing class attributes
Cleber Rosa
crosa at redhat.com
Wed Nov 28 18:07:04 UTC 2018
On 11/28/18 12:30 PM, Brian J. Murrell wrote:
> Any opinions on the preference of initializing Test class attributes in
> setUp() vs. the more traditional __init__()?
>
> I.e. if my tearDown() is:
>
> def tearDown(self):
> print self.foo
>
> self.foo needs to be initialized. Typically in python objects, this is
> done in __init__(), but given that avocado always runs setUp(), it
> could be done at the start of it.
>
> I wonder what the preferred method is.
>
The general guideline is to use __init__() for your class instance
needs, and use setUp() for getting your test ready to run.
Given that the __init__() interface is used by the test runner, and
having the minimal amount of code there will minimize problems with
runner<->test communication, I'd leave it alone as much as possible and
use setUp() instead.
> Cheers,
> b.
>
Cheers!
--
Cleber Rosa
[ Sr Software Engineer - Virtualization Team - Red Hat ]
[ Avocado Test Framework - avocado-framework.github.io ]
[ 7ABB 96EB 8B46 B94D 5E0F E9BB 657E 8D33 A5F2 09F3 ]
More information about the Avocado-devel
mailing list