web-dev-qa-db-ja.com

Noseを使用してディレクトリ内のすべてのテストを実行する

Linuxシェルに1行入力して、現在のディレクトリですべてのテストを実行できるようにする必要があります。一部のディレクトリでは、これは正常に機能します。しかし、他の人では、「nosetests」と入力してもテストは実行されません。テストを個別に呼び出すと実行されますが、すべて自動的に実行する必要があります。これは機能しないディレクトリの1つです:

/extwebserver
    __init__.py
    test_Detection.py
    test_Filesystem.py 
    test_Hardware.py
    ...

親ディレクトリで「nosetests」を実行すると、特定のサブディレクトリ内のすべてのテストが実行されますが、/ extwebserverや他のサブディレクトリ、または親ディレクトリ自体からのテストは実行されません。

[〜#〜] edit [〜#〜]出力は次のとおりです。

matthew@Matthew-Laptop:~/Documents/ParkAssist/m3/linux/appfs/master/usr/bin/piopio/testing$ nosetests -vv --collect-only
nose.selector: INFO: /home/matthew/Documents/ParkAssist/m3/linux/appfs/master/usr/bin/piopio/testing/baseTestCase.py is executable; skipped
nose.selector: INFO: /home/matthew/Documents/ParkAssist/m3/linux/appfs/master/usr/bin/piopio/testing/extwebserver/run.py is executable; skipped
nose.selector: INFO: /home/matthew/Documents/ParkAssist/m3/linux/appfs/master/usr/bin/piopio/testing/extwebserver/test_Detection.py is executable; skipped
nose.selector: INFO: /home/matthew/Documents/ParkAssist/m3/linux/appfs/master/usr/bin/piopio/testing/extwebserver/test_Filesystem.py is executable; skipped
nose.selector: INFO: /home/matthew/Documents/ParkAssist/m3/linux/appfs/master/usr/bin/piopio/testing/extwebserver/test_Hardware.py is executable; skipped
nose.selector: INFO: /home/matthew/Documents/ParkAssist/m3/linux/appfs/master/usr/bin/piopio/testing/extwebserver/test_Mode.py is executable; skipped
nose.selector: INFO: /home/matthew/Documents/ParkAssist/m3/linux/appfs/master/usr/bin/piopio/testing/extwebserver/test_System.py is executable; skipped
nose.selector: INFO: /home/matthew/Documents/ParkAssist/m3/linux/appfs/master/usr/bin/piopio/testing/extwebserver/test_View.py is executable; skipped
nose.selector: INFO: /home/matthew/Documents/ParkAssist/m3/linux/appfs/master/usr/bin/piopio/testing/extwebserver/test_Webserver.py is executable; skipped
nose.selector: INFO: /home/matthew/Documents/ParkAssist/m3/linux/appfs/master/usr/bin/piopio/testing/mocks/bottle.py is executable; skipped
nose.selector: INFO: /home/matthew/Documents/ParkAssist/m3/linux/appfs/master/usr/bin/piopio/testing/utils/test_timestamps.py is executable; skipped
nose.selector: INFO: /home/matthew/Documents/ParkAssist/m3/linux/appfs/master/usr/bin/piopio/testing/testCamera.py is executable; skipped
nose.selector: INFO: /home/matthew/Documents/ParkAssist/m3/linux/appfs/master/usr/bin/piopio/testing/testCameraManager.py is executable; skipped
nose.selector: INFO: /home/matthew/Documents/ParkAssist/m3/linux/appfs/master/usr/bin/piopio/testing/testMainControllerServer.py is executable; skipped
nose.selector: INFO: /home/matthew/Documents/ParkAssist/m3/linux/appfs/master/usr/bin/piopio/testing/testMode.py is executable; skipped
nose.selector: INFO: /home/matthew/Documents/ParkAssist/m3/linux/appfs/master/usr/bin/piopio/testing/testPASEServerClient.py is executable; skipped
nose.selector: INFO: /home/matthew/Documents/ParkAssist/m3/linux/appfs/master/usr/bin/piopio/testing/testView.py is executable; skipped
nose.selector: INFO: /home/matthew/Documents/ParkAssist/m3/linux/appfs/master/usr/bin/piopio/testing/testViewsManager.py is executable; skipped
nose.selector: INFO: /home/matthew/Documents/ParkAssist/m3/linux/appfs/master/usr/bin/piopio/testing/test_commission/test_FSM.py is executable; skipped
nose.selector: INFO: /home/matthew/Documents/ParkAssist/m3/linux/appfs/master/usr/bin/piopio/testing/test_commission/test_Webserver.py is executable; skipped
test_add (testing.utils.test_config.test_config) ... ok
test_add_set (testing.utils.test_config.test_config) ... ok
test_load (testing.utils.test_config.test_config) ... ok
test_load_valid (testing.utils.test_config.test_config) ... ok
test_modify_set (testing.utils.test_config.test_config) ... ok
test_save (testing.utils.test_config.test_config) ... ok
test_update (testing.utils.test_config.test_config) ... ok
test_get_full_version (testing.utils.test_controller.test_controller) ... ok
test_get_hwaddr (testing.utils.test_controller.test_controller) ... ok
test_get_ip (testing.utils.test_controller.test_controller) ... ok
test_get_netmask (testing.utils.test_controller.test_controller) ... ok
test_get_version (testing.utils.test_controller.test_controller) ... ok
test_FloatEncoder (testing.utils.test_fileio.test_fileio) ... ok
test_read_file (testing.utils.test_fileio.test_fileio) ... ok
test_read_json_string (testing.utils.test_fileio.test_fileio) ... ok
test_system_to_text (testing.utils.test_fileio.test_fileio) ... ok
test_write_file (testing.utils.test_fileio.test_fileio) ... ok
test_get_hwaddr (testing.utils.test_netdev.test_netdev) ... ok
test_get_ip (testing.utils.test_netdev.test_netdev) ... ok
test_get_netmask (testing.utils.test_netdev.test_netdev) ... ok
test_set_datetime (testing.utils.test_syncdatetime.test_syncdatetime) ... ok
test_cast (testing.utils.test_tools.test_tools) ... ok
test_get_image (testing.testdetection.test_CameraGuardian.test_CameraGuardian) ... ok

----------------------------------------------------------------------
Ran 23 tests in 0.003s
23
Matt

Python Testing:Beginner's Guide by Daniel Arbuckleから:

Noseは、名前がtestおよびTestで始まるか、'_''.'、または'- 'の後に続くディレクトリおよびモジュールでテストを探します。 testまたはTest。これがデフォルトですが、実際にはすべてではありません。

noseユニットテストフレームワークの拡張入門 は、以下を実行することにより、noseのテスト検出アルゴリズムからの詳細な出力を確認できることを示しています。

nosetests -vv --collect-only

上記をディレクトリで実行すると、Noseが実行可能ファイルをスキップすることに気付きました。それが問題である場合は、ファイルモードを実行不可に変更する必要があります。 Mac OS XまたはLinuxでは、これは次の方法で実行できます。

chmod 644 file.py

または類似。

モジュール/ファイルがインポートセーフであることがわかっている場合は、--exeオプションを指定してNoseを実行し、「python実行可能なモジュールでテストを探す」」( `から男性の鼻テスト):

nosetests --exe
54
Matthew Rankin

コマンドラインで--exeを使用すると、実行可能ファイルを有効なテストと見なすようにnoseに強制できます。毎回--exeを書くのに飽きたら、次の行を入力できます。

exe = True

youtホームディレクトリの.noserc(unix/linuxの場合)またはnose.cfg(Windowsの場合)ファイル。

14
Euribates