Dne 06. 11. 18 v 18:24 Brian J. Murrell napsal(a):
> On Tue, 2018-11-06 at 17:20 +0100, Lukáš Doktor wrote:
>>
>> The ":avocado: recursive" is used for test discovery. The main
>> difference is that for test discovery we don't load the modules.
>> Instead we use static analysis (using `ast`) to detect whether
>> certain file is python and contains something inherited from
>> `avocado.Test`.
>
> Ahhh.
>
> So that might be related to the issue I'm having:
>
> util/apricot/apricot/__init__.py:
> ```
> __all__ = ['ApricotTest']
>
> from apricot.test import ApricotTest
> ```
>
> util/apricot/apricot/test.py:
> ```from avocado import Test
>
> class ApricotTest(Test):
> def setUp(self):
> self.log.info("setUp() executed from Apricot")
>
> def some_useful_method(self):
> return True
>
> ```
>
> avocado detects that:
>
> util/apricot/test_example.py
> ```
> #!/usr/bin/python
>
> '''
> bla bla bla
> '''
>
> import sys
> sys.path.append('./')
>
> from apricot import ApricotTest
>
> class MyTest(ApricotTest):
> """
> :avocado: recursive
> """
> def setUp(self):
> super(MyTest, self).setUp()
> self.log.info("setUp() executed from test_example.py")
>
> def test(self):
> """
> :avocado: tags=all
> """
>
> print "test()"
> self.assertTrue(self.some_useful_method())
> ```
>
> is an instrumented avocado test and produces:
>
> ```
> 2018-11-06 12:16:34,560 test L0240 INFO | START
> 1-util/apricot/test_example.py:MyTest.test
> 2018-11-06 12:16:34,695 test L0005 INFO | setUp() executed from
> Apricot
> 2018-11-06 12:16:34,695 test_example L0018 INFO | setUp() executed from
> test_example.py
> 2018-11-06 12:16:34,695 output L0655 DEBUG| test()
> ```
>
> However when much the same file is in a different location outside of
> the apricot/ dir:
> ./test_example.py
> ```
> #!/usr/bin/python
>
> '''
> bla bla bla
> '''
>
> import sys
> sys.path.append('./util/apricot')
>
> from apricot import ApricotTest
>
> class MyTest(ApricotTest):
> """
> :avocado: recursive
> """
> def setUp(self):
> super(MyTest, self).setUp()
> self.log.info("setUp() executed from test_example.py")
>
> def test(self):
> """
> :avocado: tags=all
> """
>
> print "test()"
> self.assertTrue(self.some_useful_method())
> ```
>
> is not detected as an instrumented test and it runs it as a simple
> test:
>
> ```
> 2018-11-06 12:22:51,764 test L0240 INFO | START 1-test_example.py
> 2018-11-06 12:22:51,898 process L0389 INFO | Running
> '/home/brian/test_example.py'
> 2018-11-06 12:22:52,275 process L0499 INFO | Command
> '/home/brian/test_example.py' finished with 0 after 0.372878074646s
> 2018-11-06 12:22:52,276 test L0858 INFO | Exit status: 0
> ```
>
> Why is the latter not being detected as an instrumented avocado test?
> Yes, this is related to the fact that the code is not being executed, but only analyzed on discovery. You could save yourself a lot of trouble by simply deploying your subclass properly (using "python setup.py develop --user" for development and "python setup.py install --user" for actual deployment). Anyway to workaround this issue you can always set PYTHONPATH directly on cmdline: ``` PYTHONPATH=./util/apricot avocado --show all run test_example.py ... avocado.test: START 1-test_example.py:MyTest.test (1/1) test_example.py:MyTest.test: avocado.test: setUp() executed from Apricot avocado.test: setUp() executed from test_example.py avocado.test: test() paramiko: test() avocado.test: PASS 1-test_example.py:MyTest.test avocado.test: PASS (0.02 s) avocado.test: Test results available in /home/medic/avocado/job-results/job-2018-11-06T20.15-07ef7c1 ... ``` Regards, Lukáš > Cheers, > b. >
signature.asc
Description: OpenPGP digital signature
