python - 使用 maven exec-maven-plugin 运行 "python -m unittest"失败

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

我正在尝试设置我的 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

我在这里做错了什么?

提前致谢!

最佳答案

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

关于python - 使用 maven exec-maven-plugin 运行 "python -m unittest"失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70828395/

相关文章:

mongodb - 具有MongoDB镜像的docker-maven-plugin在启动时挂起

python - 在Python中填充列表的列表

python - Pandas DataFrame 到 Django API

svn - 在maven pom中添加scm信息的目的是什么?

maven - 如何从 maven-antrun-plugin 执行 ant jar

python - 如何对python中复杂类中的方法进行单元测试?

python - 如何开始测试现有的 python 脚本?

Python:知道函数是从单元测试调用的吗?

python - AnTLR4:INDENT 和 DEDENT 代币

python - matplotlib 不导入 PyQt4、PyQt5 或 PySide