0
我正在执行maven构建的机器人测试用例。现在这些测试用例需要很多外部python模块。 当我直接执行它们(pybot
)时,一切正常。Maven构建多个python模块导入错误
但是,当我通过maven执行它们时,外部python模块失败。
[ ERROR ] Error in file '/home/xyz/robot/tf2jan/Tests/CLI/mycli/mycli_resources.txt': Importing test library '/home/xyz/robot/tf2jan/lib/rest/JsonValidator.py' failed: ImportError: No module named jsonselect
Traceback (most recent call last):
File "/home/xyz/robot/tf2jan/lib/rest/JsonValidator.py", line 6, in <module>
from jsonselect import jsonselect
PYTHONPATH:
/usr/lib/python2.7/dist-packages
/home/xyz/Downloads/python-jsonpath-rw
/home/xyz/Downloads/ply-3.10
/home/xyz/.m2/repository/org/robotframework/robotframework/3.0.2/Lib
/home/xyz/.m2/repository/org/robotframework/robotframework/3.0.2/robotframework-3.0.2.jar/Lib
我确实有将它们添加在Maven使用extraPathDirectories
这样的插件配置的选项:
<plugin>
<groupId>org.robotframework</groupId>
<artifactId>robotframework-maven-plugin</artifactId>
<version>1.4.7</version>
<executions>
<execution>
<goals>
<goal>acceptance-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<skip>${skipRobotTests}</skip>
<testCasesDirectory>/home/xyz/robot/tf2jan/Tests/CLI/mycli</testCasesDirectory>
<variableFiles>/home/xyz/robot/tf2jan/etc/environments/mycli_env.py</variableFiles>
<outputDirectory>${project.basedir}/target/robotframework-reports/</outputDirectory>
<tests>mycli_help_usage</tests>
<extraPathDirectories>
<extraPathDirectory>/usr/lib/python2.7/dist-packages</extraPathDirectory>
<extraPathDirectory>/home/xyz/Downloads/python-jsonpath-rw</extraPathDirectory>
<extraPathDirectory>/home/xyz/Downloads/ply-3.10</extraPathDirectory>
</extraPathDirectories>
<externalRunner>
<excludeDependencies>false</excludeDependencies>
<jvmArgs>
<jvmArg>${surefireArgLine}</jvmArg>
</jvmArgs>
</externalRunner>
</configuration>
</execution>
</executions>
</plugin>
但是这个解决方案,我将最终路径,增加过多的模块,这些模块会使pom文件复杂化。 是否有任何配置可以自动解决这些模块依赖关系或任何其他较短的解决方案?
是的,但是对于一个有知道什么是所需的外部组件。想想在测试套件中添加了新的模块依赖项时,开发人员可以将其添加到本地PYTHONPATH中,但CI系统不会知道该添加项,并且会失败构建。 – ASR
但是,如果您向PYTHONPATH中添加诸如“somePath/external-lib-directories”之类的内容,然后将每个外部库放入此文件夹内,它会不会起作用?还是仅仅是在你的环境中你不能做的事情? – Adonis
这会起作用,而且我当然可以在我的本地环境中执行此操作,但构建和测试套件触发的CI框是不同的框,并且不受开发团队的关注。每次添加新的依赖关系时,我们都不应该要求他们添加新模块。 – ASR