4
python setup.py test
に組み込まれたunittest
パッケージの代わりにunittest2
パッケージをテストに使用させるにはどうすればよいですか?python setup.pyテストでunittest2を使用する方法
python setup.py test
に組み込まれたunittest
パッケージの代わりにunittest2
パッケージをテストに使用させるにはどうすればよいですか?python setup.pyテストでunittest2を使用する方法
tests
というディレクトリにという名前のファンクションを定義した__init__.py
ファイルが含まれているとします。
from setuptools import Command
from setuptools import setup
class run_tests(Command):
"""Runs the test suite using the ``unittest2`` package instead of the
built-in ``unittest`` package.
This is necessary to override the default behavior of ``python setup.py
test``.
"""
#: A brief description of the command.
description = "Run the test suite (using unittest2)."
#: Options which can be provided by the user.
user_options = []
def initialize_options(self):
"""Intentionally unimplemented."""
pass
def finalize_options(self):
"""Intentionally unimplemented."""
pass
def run(self):
"""Runs :func:`unittest2.main`, which runs the full test suite using
``unittest2`` instead of the built-in :mod:`unittest` module.
"""
from unittest2 import main
# I don't know why this works. These arguments are undocumented.
return main(module='tests', defaultTest='suite',
argv=['tests.__init__'])
setup(
name='myproject',
...,
cmd_class={'test': run_tests}
)
今すぐpython setup.py test
実行私のカスタムtest
のコマンドを実行している:
私のソリューションは、unittest2
を使用して自分のtest
コマンドでデフォルトpython setup.py test
コマンドを交換することです。
しかし、 'python setup.py test'は' setup() 'の' tests_require'リストから自動的にパッケージをインストールしないので、この解決法を使うと 'unittest2'を手動でインストールする必要があります。 – argentpepper