0

I am writing a custom testing library for Robot Framework in Python and I want to import it like this:

Library         CustomLibrary

I put the folder containing the source code on the PYTHONPATH but I am still getting the error: Importing test library 'CustomLibrary' failed: ImportError: No module named CustomLibrary

The CustomLibrary class is defined in the __init__.py file, like in the AppiumLibrary like this:

from CustomLibrary.keywords import *

class CustomLibrary(_CustomKeywords):
    ROBOT_LIBRARY_SCOPE = 'GLOBAL'

How can I solve this problem, so I can import it in Robot Framework? I want to keep the class definition inside the init file.

Fogarasi Norbert
  • 650
  • 2
  • 14
  • 34

1 Answers1

3

You need to make sure that the folder containing CustomLibrary is on PYTHONPATH.

For example, the following works as expected for me:

  1. create a folder in /tmp named CustomLibrary
  2. create a file named /tmp/CustomLibrary/__init__.py
  3. define a class named CustomLibrary in /tmp/CustomLibrary/__init__.py
  4. define a method in the CustomLibrary class
  5. import the library in a test with Library CustomLibrary
  6. add /tmp to PYTHONPATH and run robot. For example, robot --pythonpath /tmp example.robot
Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685