Dne 05. 11. 18 v 22:59 Brian J. Murrell napsal(a): > Can I subclass avocado as described at > > https://avocado-framework.readthedocs.io/en/latest/SubclassingAvocado.html > > with 52.1? > > I tried duplicating[1] the structure described there exactly and > running the test_example.py passes but I don't see any of the > self.log.info() messages in the job.log. > > Cheers, > b. > > [1] With the exception of putting "sys.path.append('./')" before the > "from apricot import ApricotTest" because I don't really want to > install my subclass into my per-user python library using setup.py. >
Dear Brian,
it looks like you had to make more changes to get this working without
deploying your classes, anyway it should work (and we use it heavily). The
simplest way to give this a try would be:
test.py:
```
from avocado import Test
class ApricotTest(Test):
def setUp(self):
self.log.info("Apricot setUp")
def some_useful_method(self):
return True
class MyTest(ApricotTest):
"""
:avocado: recursive
"""
def test(self):
self.assertTrue(self.some_useful_method())
```
Slightly advanced version still without deploying your subclass:
apricot/test.py:
```
from avocado import Test
class ApricotTest(Test):
def setUp(self):
self.log.info("Apricot setUp")
def some_useful_method(self):
return True
```
apricot/__init__.py:
```
__all__ = ['ApricotTest']
from .test import ApricotTest
```
test_example.py
```
__all__ = ['ApricotTest']
from .test import ApricotTest
[medic@localhost apricot ]$ cat test_example.py
import sys
sys.path.append('./')
from apricot import ApricotTest
class MyTest(ApricotTest):
"""
:avocado: recursive
"""
def test(self):
self.assertTrue(self.some_useful_method())
```
both work well and "avocado run test_example.py" shows:
```
2018-11-06 08:30:56,165 test L0240 INFO | START
1-test_example.py:MyTest.test
2018-11-06 08:30:56,202 test L0005 INFO | Apricot setUp
2018-11-06 08:30:56,213 test L0750 INFO | PASS
1-test_example.py:MyTest.test
```
in the output using "Avocado 52.1".
I can imagine one possible issue, do you override "__init__" of your "Test"
class? If so make sure to call the "super(ApricotTest, self).__init__(...)" to
initialize the loggers and everything. Anyway I'd strongly suggest deploying
your library instead of "sys.path" trickery. You can use `--user` to only
deploy this for your user. Cleaning after such deployment is simple even when
you lost track of the names by looking at `rm
~/.local/lib/python$version/site-packages/`.
If this did not help, please send more detailed information (similarly to what
I did), ideally with results attached (or at least the output of `avocado
--show all -- test_apricot.py`).
Kind regards,
Lukáš
signature.asc
Description: OpenPGP digital signature
