Importing Robot Framework Libraries

1,060 views
Skip to first unread message

Martin Taylor

unread,
Sep 8, 2009, 1:47:12 PM9/8/09
to robotframework-users
The Robot Framework documentation talks about how to import libraries
that are implemented as a class in a module:

"The name of a test library that is used when a library is imported is
the same as the name of the module or class implementing it. For
example, if you have a Python module MyLibrary (that is, the file
MyLibrary.py), it will create a library with a name MyLibrary.
Similarly, a Java class YourLibrary, when it is not in any package,
creates a library with exactly that name.
Python classes are always inside a module. If the name of a class
implementing a library is the same as the name of the module, Robot
Framework allows dropping the module name when importing the library.
For example, the class MyLib in the MyLib.py file can be used as a
library with the name MyLib. If the module name and class name are
different, libraries must be taken into use using both module and
class names, such as mymodule.MyLibrary."

All my libraries are structured as Classes inside Modules inside
Packages, which is not discussed above. For example:

MyPackage (a folder under C:\Python25\Lib\site-packages)
|
+-- __init__.py (The main "Module"? file containing the definition
of a class called "MyPackage")
|
+-- AnotherClass.py (Another module that I want to import as a
library. It contains the definition of a class called "AnotherClass")

I've tried using:

Library MyPackage.AnotherClass

and

Library MyPackage.AnotherClass.AnotherClass

in Robot Framework and neither imports correctly. What am I doing
wrong here? Does EVERY Robot Framework library need to be in its own
package with a __init__.py file containing the class definition?

Martin Taylor

unread,
Sep 8, 2009, 2:29:44 PM9/8/09
to robotframework-users
Forget it. This:

Library MyPackage.AnotherClass.AnotherClass

worked. There were build issues masking the problem.

Sorry to trouble you all.

Martin

Pekka Klärck

unread,
Sep 8, 2009, 3:13:14 PM9/8/09
to cmta...@ti.com, robotframework-users
2009/9/8 Martin Taylor <cmta...@ti.com>:

>
> Forget it.  This:
>
> Library  MyPackage.AnotherClass.AnotherClass
>
> worked.  There were build issues masking the problem.

Great that you got it working. Notice also that if you would in your
__init__.py have "from AnotherClass import AnotherClass" you ought to
be able to take the library into use with name
"MyPackage.AnotherClass".

Cheers,
.peke

Reply all
Reply to author
Forward
0 new messages