gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 02:34:01 24 4
gpt4 key购买 nike

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com