【问题标题】:Running "python -m unittest" failing with maven exec-maven-plugin使用 maven exec-maven-plugin 运行“python -m unittest”失败
【发布时间】:2022-01-24 02:32:31
【问题描述】:

我正在尝试设置我的 maven 构建,以便 mvn test 除了运行我的 Java 测试之外还运行我的 python 测试。我正在尝试使用exec-maven-plugin 来执行此操作。

我的pom.xml 有:

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>exec-maven-plugin</artifactId>
  <version>3.0.0</version>
  <executions>
    <execution>
      <configuration>
        <executable>python3</executable>
        <workingDirectory>${project.basedir}/src/main/resources/scripts/</workingDirectory>
        <arguments>
          <argument>-m</argument>
          <argument>unittest</argument>
          <argument>discover</argument>
          <argument>-p</argument>
          <argument>'*_test.py'</argument>
        </arguments>
      </configuration>
      <id>python-test</id>
      <phase>test</phase>
      <goals>
        <goal>exec</goal>
      </goals>
    </execution>
  </executions>
</plugin>

我的项目结构是这样的:

.
├── pom.xml
├── src
│   ├── main
│   │   └── resources
│   │       ├── scripts
│   │       │   ├── __init__.py
│   │       │   ├── foo.py
│   │       │   ├── foo_test.py

当我尝试从项目根目录运行它时:

mvn exec:exec@python-test

我运行了 0 个测试:

----------------------------------------------------------------------
Ran 0 tests in 0.000s

OK

但是,如果我手动执行此操作,它可以正常工作:

cd src/main/resources/scripts 
python3 -m unittest discover -p '*_test.py' 
...
----------------------------------------------------------------------
Ran 3 tests in 0.010s

我在这里做错了什么?

提前致谢!

【问题讨论】:

    标签: python maven python-unittest maven-exec-plugin


    【解决方案1】:

    原来这一行的单引号是问题所在:&lt;argument&gt;'*_test.py'&lt;/argument&gt;。包裹文件匹配器的单引号被解释为-p "'*_test.py'" 并且不匹配任何文件。删除它们解决了这个问题。

    【讨论】:

      猜你喜欢
      • 2015-01-23
      • 2011-07-03
      • 2016-01-31
      • 2011-03-29
      • 2014-04-19
      • 2014-04-23
      • 2018-07-09
      • 2018-10-19
      相关资源
      最近更新 更多