nose2は、shebang行に設定されているすべてのPythonを使用します。
この例で検証
python2.7 /usr/local/bin/nose2
:
test.py:
def test_the_program():
print "foo"
を(実行可能ファイルとパスがコンピュータに異なる場合があります)python2プロジェクトの使用をテストするには
とpython3:
python2.7と
$ python3 /usr/local/bin/nose2
======================================================================
ERROR: test (nose2.loader.ModuleImportFailure)
----------------------------------------------------------------------
ImportError: Failed to import test module: test
(...)
print "hans"
^
SyntaxError: Missing parentheses in call to 'print'
----------------------------------------------------------------------
Ran 1 test in 0.000s
FAILED (errors=1)
:[本](http://nose2.readthedocs.io/en/latest/differences.html)文書nose2によれば
$ python2.7 /usr/local/bin/nose2
foo
.
----------------------------------------------------------------------
Ran 1 test in 0.000s
OK
は、Python 2.6、2.7をサポートしなければなりません、3.2以上。あなたはpython2インタプリタを使用していますか? python2とpython3の間には多くの[相違点](http://sebastianraschka.com/Articles/2014_python_2_3_key_diff.html)があります。 Python3インタプリタでpython2コードを実行しようとするとエラーが発生しました。 –
http://stackoverflow.com/questions/9079036/detect-python-version-at-runtimeに続いて、 'print(sys.version_info [0])'を含むスクリプトを使ってPythonのバージョンをチェックし、 '2 '。 –
なお、「そのまま」動作した別のテストプログラムは、[pytest](http://doc.pytest.org/en/latest/)です。そのテストディスカバリ方法は少し異なります(たとえば、テストスクリプトの名前を 'test_'で始めるか、' _test'で終わらせる必要があります)が、ターミナル出力は 'nose2'よりも使いやすいものです。 –