Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
164 views
in Technique[技术] by (71.8m points)

python - Run all Tests in Directory Using Nose

I need to be able to run all tests in the current directory by typing one line in the Linux shell. In some directories, this works fine. But in others, when I type "nosetests" no tests are run. The tests will run if I call for them individually but I need them to all run automatically. Here is one of the directories that won't work:

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

When I run "nosetests" in the parent directory, all tests in a certain subdirectory are run but no tests from /extwebserver or other subdirectories or the parent directory itself are run.

EDIT Here's the output:

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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

From Python Testing: Beginner's Guide by Daniel Arbuckle:

Nose looks for tests in directories and modules whose names start with test and Test, or contain a '_', '.', or '-' followed by test or Test. That's the default, but it's not actually the whole story.

An Extended Introduction to the nose Unit Testing Framework shows that you can see a verbose output from nose's test discovery algorithm by running:

nosetests -vv --collect-only

When I ran the above on a directory, I noticed that Nose skips executable files. If that's your problem, you'll need to change the file mode to non-executable. On Mac OS X or Linux, this can be accomplished with:

chmod 644 file.py

or similar.

If you know that your modules/files are import-safe, then you can run Nose with the --exe option to "look for tests in python modules that are executable" (from `man nosetests):

nosetests --exe

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...