2

My Robot Project looks like this:

lib/
   __init__.py
   utils.py
   foo.py
__init__.robot
sample.robot

I write some util functions into utils.py and use it in foo.py. However, when I run robot with sample.robot, it throws an exception:

[ ERROR ] Error in file '/Users/tuanchauict/Desktop/demo/sample.robot': Importing test library '/Users/tuanchauict/Desktop/demo/lib/foo.py' failed: ImportError: attempted relative import with no known parent package
Traceback (most recent call last):
  File "/Users/tuanchauict/Desktop/demo/lib/foo.py", line 1, in <module>
    from .lib.utils import *
PYTHONPATH:
  /Users/tuanchauict/.local/share/virtualenvs/demo-XFo70VU1/bin
  /Users/tuanchauict/.local/share/virtualenvs/demo-XFo70VU1/lib/python36.zip
  /Users/tuanchauict/.local/share/virtualenvs/demo-XFo70VU1/lib/python3.6
  /Users/tuanchauict/.local/share/virtualenvs/demo-XFo70VU1/lib/python3.6/lib-dynload
  /usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python3.6
  /Users/tuanchauict/.local/share/virtualenvs/demo-XFo70VU1/lib/python3.6/site-packages
==============================================================================
Sample
==============================================================================
Demo                                                                  | FAIL |
No keyword with name 'Test Keyword' found.
------------------------------------------------------------------------------
Sample                                                                | FAIL |
1 critical test, 0 passed, 1 failed
1 test total, 0 passed, 1 failed
==============================================================================
Output:  /Users/tuanchauict/Desktop/demo/output.xml
Log:     /Users/tuanchauict/Desktop/demo/log.html
Report:  /Users/tuanchauict/Desktop/demo/report.html

The content of files:

utils.py

def foo():
    pass

foo.py

from .lib.utils import *  # I also tried `from .utils import *`

def test_keyword():
    pass 

sample.robot

*** Settings ***
Library  lib/foo.py


*** Test Cases ***

Demo
    Test Keyword

I run with Python3.6

Tuan Chau
  • 1,243
  • 1
  • 16
  • 30

0 Answers0