gpt4 book ai didi

python - 如何从目录中给出python文件的路径

转载 作者:行者123 更新时间:2023-12-01 04:26:29 26 4
gpt4 key购买 nike

我在项目文件夹中有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 - 如何从目录中给出python文件的路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33060989/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com