我正在从maven build执行机器人测试用例。现在这些测试用例需要许多外部python模块。
当我直接执行它们(pybot
)时,一切正常。
但是当我通过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
我可以选择使用extraPathDirectories
在maven插件配置中添加它们,如下所示:
<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文件复杂化。 是否有任何配置可以自动解决这些模块依赖关系或任何其他更短的解决方案?
答案 0 :(得分:0)
我建议,因为你没有在Maven中对Python库进行依赖管理,所以:
添加到您的PYTHONPATH(由Maven检查,请参阅输出PYTHONPATH:
)库的位置
编辑如果您想避免必须手动安装到CI框的依赖项,您可以尝试使用此maven插件:
<plugin>
<groupId>com.googlecode.maven-download- plugin</groupId>
<artifactId>download-maven-plugin</artifactId>
<version>1.3.0</version>
<executions>
<execution>
<id>install-a-dependency</id>
<phase>pre-integration-test</phase>
<goals>
<goal>wget</goal>
</goals>
<configuration>
<url>the_dependency_url</url>
<unpack>true</unpack>
<outputDirectory>${project.build.directory}/jbpm-3.1.4</outputDirectory>
<md5>df65b5642f33676313ebe4d5b69a3fff</md5>
</configuration>
</execution>
</executions>
</plugin>
请参阅https://github.com/maven-download-plugin/maven-download-plugin