[Avocado-devel] Test assumptions question.

Dmitry Monakhov dmonlist at gmail.com
Wed Sep 14 12:57:25 UTC 2016


Fam Zheng <famz at redhat.com> writes:

> On Wed, 09/14 10:51, Dmitry Monakhov wrote:
>> class AvocadoRelease(Test):
>> 
>>     def setUp(self):
>>         self.log.info("do setUp: install requirements, fetch source")
>> 
>>     def test_a(self):
>>         self.log.info("do test_a: inspekt lint")
>> 
>>     def test_b(self):
>> 	self.log.info("do test_b: inspekt style")
>> 
>>     def tearDown(self):
>>         self.log.info("do tearDown")
>> My assumptions was that test sequence will be:
>> do setUp
>> do test_a: inspekt lint
>> do test_b: inspekt style
>> do tearDown
>> But it is appeared that each testcase is wrapped with setUp()/teerDown()
>> ####
>> START 1-simpletest.py:AvocadoReliase.test_a
>> do setUp: install requirements, fetch source
>> do test_a: inspekt lint
>> do tearDown
>> PASS 1-simpletest.py:AvocadoReliase.test_a
>> START 2-simpletest.py:AvocadoReliase.test_b
>> do setUp: install requirements, fetch source
>> do test_b: inspekt style
>> do tearDown
>> PASS 2-simpletest.py:AvocadoReliase.test_b
>> ####
>> This is not obvious. And makes it hard to divide test to
>> fine-grained testcases because setUp/teerDown() for each test may
>> be too intrusive. What is convenient way implement this scenario?
>
> This is the interface of Python's unittest.TestCase (base class of avocado Test
> class).  It also offers setUpClass and tearDownClass that do what you want
> above.
>
> See also `pydoc unittest.TestCase`.
Indeed. But avocado.Test() does not call setUpClass/tearDownClass.
it call only setUp/tearDown. AIFAU this is done that way because
each test is executed in supbrocess. See runner.py:TestRunner.run_test:
    proc = multiprocessing.Process(target=self._run_test,
                                       args=(test_factory, queue,))

IMHO this is a bit unusual, but cool because allow to support
concurrent test execution in future.
IMHO It would be nice document it somewhere, for example add compat mode where:
setUpClass/tearDownClass are called similar to setUp/tearDown, but
dump warning in a log.

BTW: Are any chance to implement parallel executions in near future ?
https://trello.com/c/xNeR2slj/255-support-running-tests-in-parallel
> Fam
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 472 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/avocado-devel/attachments/20160914/4f7fb380/attachment.sig>


More information about the Avocado-devel mailing list