如何从目录中为 python 文件提供路径
How to give path for python file from directory
我在项目文件夹中有 python 个文件 tests.py,我可以按如下方式调用方法:
Library tests.Tests
但我将 tests.py 移动到同一项目文件夹中的文件夹 python_tests,但我似乎无法找到正确的路径。
我试过下面的东西
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
您必须使用路径名(绝对或相对于测试)或路径上模块的模块名称,但不能混合使用这两种技术。
- 如果
python_tests
是你的 PYTHONPATH 上的一个包,python_tests.tests.Tests
应该可以。
- 如果您将
python_tests
的路径放在 PYTHONPATH 中,tests.Tests
应该可以工作。
- 如果 python_tests 不是包,
python_tests/tests/Tests.py
应该可以。
机器人框架用户指南中标题为 Specifying library to import 的部分涵盖了所有内容。以下是一些摘录:
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.
我在项目文件夹中有 python 个文件 tests.py,我可以按如下方式调用方法:
Library tests.Tests
但我将 tests.py 移动到同一项目文件夹中的文件夹 python_tests,但我似乎无法找到正确的路径。 我试过下面的东西
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
您必须使用路径名(绝对或相对于测试)或路径上模块的模块名称,但不能混合使用这两种技术。
- 如果
python_tests
是你的 PYTHONPATH 上的一个包,python_tests.tests.Tests
应该可以。 - 如果您将
python_tests
的路径放在 PYTHONPATH 中,tests.Tests
应该可以工作。 - 如果 python_tests 不是包,
python_tests/tests/Tests.py
应该可以。
机器人框架用户指南中标题为 Specifying library to import 的部分涵盖了所有内容。以下是一些摘录:
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.