[Avocado-devel] Appropriate test+library layout?

Paul Graydon paul.graydon at oracle.com
Sun Dec 10 21:32:09 UTC 2017


Hi all,

We're looking at using Avocado to carry out functional testing.  Of
particular interest is the possibility of providing dimensions for
testing (need to repeat the same tests but with one or two slight
differences each time).

I'm running in to some quirks that indicate I'm either approaching
things wrong, or I need to work around it.  I guess I'm seeking advice
on good test layout or the best approach to take with avocado.

Here's a toy example that reflects the approach we started with:

$ find .
.
./foo
./foo/__init__.py
./foo/util.py
./tests
./tests/__init__.py
./tests/test_foo.py


$ cat foo/util.py
def return_true():
    print "Returning true"
    return True


$ cat tests/test_foo.py
from foo.util import return_true
from avocado import Test


class TestFooUtil(Test):

    def test_return_true(self):
        assert return_true()


The __init__.py files are blank.

If I run this from ./ it fails because it can't import foo :

$ avocado run .

...

ImportError: No module named foo.util

...


If I drop sys and print sys.path in to test_foo.py it looks like avocado
is executing the code from within the tests directory, so imports would
need to be relative.  I can meddle with the path to make things work, if
needs be.

If I quickly modify that test_foo.py file and turn it in to a standard
unittest, I can invoke it from the parent directory and have it import
correctly:

$ python -m unittest -c tests.test_foo
Returning true
.
----------------------------------------------------------------------
Ran 1 test in 0.000s

OK

Or allow it to discover the tests itself:

$ python -m unittest discover
Returning true
.
----------------------------------------------------------------------
Ran 1 test in 0.000s

OK
 

Is there a way to approach this using avocado that results in it finding
all the tests when run from a directory, but executing the python from
that context, instead of the directory where it found the tests?
Should I be laying things out in a different fashion?  I don't see
anything applicable in the documentation, but there's every good chance
I'm just reading it wrong!

There's lots of tests planned that we're hoping to keep structured
cleanly under various subdirectories, and a fair bit of utility code
that is going to be necessary to give us the test / dimensionality we
really need.

Any advice would be appreciated.

Paul


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 874 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/avocado-devel/attachments/20171210/90730111/attachment.sig>


More information about the Avocado-devel mailing list