2011/10/11 afrotypa <
ovua...@gmail.com>:
> In order to simplify importing libraries implemented as modules each
> containing multiple classes in a package, I want to be able to have
> something like this :-
>
> 1. A Package P1 in the PYTHONPATH (i.e. a directory named P1 in the
> python path)
> 2. P1 contains modules m1.py, m2.py etc.
> 3. Each of the modules contains classes M1C1, M1C2,etc M2C1, M2C2
> where MxCy denotes the yth class in the xth module.
> 4. Each of the classes implement public methods that are all keywords
> i.e. each class is a RF library.
>
> Here are the paths of the modules m1.py, m2.py and __init__.py which
> makes P1 a package ..
>
> <python_path>\P1\m1.py
> <python_path>\P1\m2.py
> <python_path>\P1\__init__.py
>
> I want to be able to import all the public methods defined in all the
> classes by simply importing the P1 package as a robot library.
>
> Simply defining an __init__.py in P1 that contains the following lines
> does not seem to accomplish this as I thought (none of the keywords
> defined in m1 or m2 are found):-
>
> from m1 import *
> from m2 import *
This imports classes M1C1, M1C2, etc.
> Then in the test suite, to import the P1 package I used the Library
> setting
>
> Library P1
This makes module P1 a library so that all the functions in the module
are keywords. Now your keywords are in the imported classes and thus
they aren't considered keywords.
> Does anyone know how this can be accomplished.?
Simplest possibility that could work is creating class P1 that
inherits all your sub test libraries:
class P1(M1C1, M1C2, ...):
pass
Since the library has same name as the module, using `| Library | P1
|` now imports class P1 from module P1. Alternatively you could build
something more fancy using either the hybrid or dynamic library APIs
explained in the User Guide.
Cheers,
.peke
--
Agile Tester/Developer/Consultant :: http://eliga.fi
Lead Developer of Robot Framework :: http://robotframework.org