3

Jenkins に統合したいシステム テストがたくさんあります。結果として、私は賢くなり、Nose の Xunit プラグインを使用して結果ファイルを生成しようと考えました。私のコードは次のようになります。


from optparse import OptionParser
from subprocess import call

from nose.plugins.xunit import Xunit as xunit
from nose.config import Config

if __name__ == "__main__":
    p = OptionParser(usage="A simple wrapper for creating JUnit XML")
    p.add_option("-v", "--verbose",
                 action="store_true", dest="verbose", default=False,
                 help="generate extra information")

    # hook in xunit plugin options
    x = xunit()
    x.add_options(p)

    (options, args) = p.parse_args()
    x.configure(options, Config())
    for test in args:
        test_args = test.split(" ")
        test_name = test_args[0]
        if options.verbose: print "running: %s" % (test_name)

        x.startTest(test_name)
        result = call(test_args, shell=True)
        if result == 0:
            x.addSuccess(test_name)
        else:
            x.addFailure(test_name, None)

    x.report()

ただし、実行すると失敗します。

17:24 ajb@sloy/x86_64 [perf_test.git] >./junitify.py -v "/bin/true" "/bin/false"
実行中: /bin/true
トレースバック (最新の呼び出しが最後):
  ファイル「./junitify.py」の 39 行目
    x.addSuccess(test_name)
  addSuccess のファイル「/usr/lib/python2.7/dist-packages/nose/plugins/xunit.py」の 239 行目
    self.stats['パス'] += 1
AttributeError: 'Xunit' オブジェクトには属性 'stats' がありません

xunit のコードを見ると、self.enabled が設定されていないことが原因です。ただし、この方法で Xunit ライブラリを使用できるかどうかは完全には明らかではありません。私がやろうとしていることは可能ですか?これは、このライブラリを初期化する方法を誤解しているだけですか? 出力を生成するために別の python ライブラリを使用する必要がありますか?

Jenkins の下で Python コードのチャンクに対して doctest 単体テストを実行するために、nose を使用するのは残念なことです。

4

0 に答える 0