0

コンテキスト: 再帰的に python を含むディレクトリunittest.TestCase:

projectdir/build.xml
projectdir/src/x.java
projectdir/distribute/p.jar
projectdir/tests/a/test1.py
projectdir/tests/a/test2.py
projectdir/tests/b/test1.py
projectdir/tests/c/test1.py
projectdir/tests/javaunittests/test2.java

そして、アリに電話してもらいたい

python -m unittest discover -s a b c

今、私はを含むディレクトリのに変換しようとしていfilesetましたか? dirsetアイデアは、python unittests を実行することです。

<apply command="python">
   <arg line="-m unittest"/>
   <arg value="-s"/>
   <dirset include="${python_unittests}"/>
</apply>

where ${python_unittests}" would refer to afileset` (ただし、方法がわかりません) は次のようになります。

<fileset id="python_unittests" include="**/*.py">
    <containsregexp expression="\(unittest.TestCase\)"/>
</fileset>

それとも私は間違っていますか、これを達成するためのより良い方法はありますか?

4

1 に答える 1

1

テストケースを含むすべての python ファイルが必要です。dirset は必要ありません。次を使用します。

<apply executable="python">
  <arg line="-m unittest"/>
  <arg value="-s"/>
  <fileset dir="projectdir" includes="**/*.py">
    <contains text="unittest.TestCase"/>
  </fileset>
</apply>

編集

コメントの後、 python.org の unittestのドキュメントを確認しました。
私が理解しているように、それで十分なはずです:

<property name="projectroot" location="foo/bar/yourprojectdir"/>
<exec executable="python" failonerror="true">
 <arg line="-m unittest discover ${projectroot} 'test*.py'"/>
</exec>

python docs セクション 26.3.3 として。テスト ディスカバリの説明:

The -s, -p, and -t options can be passed in as positional arguments in that order. The following two command lines are equivalent:

    python -m unittest discover -s project_directory -p '*_test.py'<br>
    python -m unittest discover project_directory '*_test.py'

ディスカバーは、project_directory から再帰的に機能することを期待しています。

于 2013-01-25T20:56:05.733 に答える