2011-06-13 88 views
19

我需要能夠通過在Linux shell中鍵入一行來運行當前目錄中的所有測試。在一些目錄中,這工作正常。但在另一些情況下,當我輸入「鼻子測試」時,沒有運行測試。如果我單獨調用它們,測試將運行,但我需要它們全部自動運行。這裏是行不通的目錄之一:使用鼻子在目錄中運行所有測試

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

當我運行在父目錄「nosetests」,在一定的子目錄都運行所有測試,但沒有從/ extwebserver或其他子目錄或父測試目錄本身運行。

編輯 下面是輸出:

[email protected]:~/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 
+0

@Matt:您能否提供'nosetests -vv --collect-only'的輸出,以便我們可以看到來自nose的測試發現算法的詳細輸出? – 2011-06-13 18:09:02

+0

我有一個類似的問題,我跳過了,因爲測試是可執行的..? – user2921139 2014-10-15 22:30:03

回答

45

Python Testing: Beginner's Guide由丹尼爾·阿巴克爾:

鼻子會在目錄測試和模塊的名字開始與testTest,或含有'_','.''-',然後是testTest。這是默認設置,但實際上並不是全部。

An Extended Introduction to the nose Unit Testing Framework表明,你可以通過運行看到鼻子的測試發現算法詳細輸出:

nosetests -vv --collect-only 

當我跑到上面的目錄中,我注意到,鼻子跳過的可執行文件。如果這是您的問題,則需要將文件模式更改爲不可執行文件。在Mac OS X或Linux上,這可以通過以下方式實現:

chmod 644 file.py 

或類似的。

如果你知道你的模塊/文件是進口安全的,那麼你就可以運行帶有--exe選項鼻子「看在是可執行的Python模塊測試」(從'人nosetests):

nosetests --exe 
+0

我嘗試重命名目錄,但它仍然沒有從它們收集測試。我試過了form test *和test_ *,但都沒有成功。我也用--collect-only來運行它,它列出了子目錄中可執行的文件,因此被跳過。但是我刪除了python.exe的路徑,這些文件仍被列爲可執行文件。 – Matt 2011-06-13 18:13:21

+0

嘗試將文件模式更改爲不可執行的文件的鼻子跳過。 – 2011-06-13 18:31:32

+1

chmod技巧奏效。它現在從工作目錄和所有子目錄收集所有測試。謝謝您的幫助! – Matt 2011-06-13 18:38:26

11

您可以在命令行中使用--exe強制nose將可執行文件視爲有效測試。如果你厭倦了書面方式--exe每次,你可以把線:

EXE =真

在.noserc(用於Unix/Linux操作系統)的或nose.cfg(適用於Windows)文件你的主目錄。

相關問題