简体   繁体   中英

How to give path for python file from directory

I had python file tests.py in project folder and I could call the methods as follows:

Library  tests.Tests

But I moved tests.py to folder python_tests in same project folder but I can't seem to get path right. I tried below things

Library  python_tests/tests.Tests
Library  /python_tests/tests.Tests
Library  /home/robot_project/python_tests/tests.Tests
Library  home/robot_project/python_tests/tests.Tests

You must either use a pathname (absolute, or relative to the test), or a module name for a module on your path, but you can't mix the two techniques.

  • If python_tests is a package that is on your PYTHONPATH, python_tests.tests.Tests should work.
  • If you put the path to python_tests in your PYTHONPATH, tests.Tests should work.
  • If python_tests is not a package, python_tests/tests/Tests.py should work.

This is all covered in the robot framework user guide, in the section titled Specifying library to import . Here are a couple of exerpts:

The most common way to specify a test library to import is using its name.... In these cases Robot Framework tries to find the class or module implementing the library from the module search path. Libraries that are installed somehow ought to be in the module search path automatically, but with other libraries the search path may need to be configured separately.

...

Another mechanism for specifying the library to import is using a path to it in the file system. This path is considered relative to the directory where current test data file is situated ... The main benefit of this approach is that there is no need to configure the module search path.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM