2017-02-28 57 views
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文件复杂化。 是否有任何配置可以自动解决这些模块依赖关系或任何其他较短的解决方案?

回答

0

我的建议,因为你没有在Maven的Python库依赖管理,就是:

  • 把你的库在Python
  • 的默认lib目录添加到您的PYTHONPATH (因为它是由Maven的检查,查看输出PYTHONPATH:)的库

    编辑的位置,如果你想避免手动安装到您的CI箱的依赖,你可以试试这个行家插件:

    <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

+0

是的,但是对于一个有知道什么是所需的外部组件。想想在测试套件中添加了新的模块依赖项时,开发人员可以将其添加到本地PYTHONPATH中,但CI系统不会知道该添加项,并且会失败构建。 – ASR

+0

但是,如果您向PYTHONPATH中添加诸如“somePath/external-lib-directories”之类的内容,然后将每个外部库放入此文件夹内,它会不会起作用?还是仅仅是在你的环境中你不能做的事情? – Adonis

+0

这会起作用,而且我当然可以在我的本地环境中执行此操作,但构建和测试套件触发的CI框是不同的框,并且不受开发团队的关注。每次添加新的依赖关系时,我们都不应该要求他们添加新模块。 – ASR