使用鼻子在目录中运行所有测试 [英] Run all Tests in Directory Using Nose

查看:72
本文介绍了使用鼻子在目录中运行所有测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要能够通过在Linux shell中键入一行来运行当前目录中的所有测试.在某些目录中,这可以正常工作.但是在其他情况下,当我键入"nosetests"时,则不会运行任何测试.如果我单独要求进行测试,则将运行这些测试,但我需要它们全部自动运行.这是无法使用的目录之一:

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
    ...

当我在父目录中运行"nosetests"时,将运行某个子目录中的所有测试,但不会运行/extwebserver或其他子目录或父目录本身的测试.

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.

编辑 这是输出:

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

推荐答案

来自 Python测试: Daniel Arbuckle撰写的《初学者指南》 :

Nose在名称以testTest开头或包含'_''.''-'后跟testTest的目录和模块中查找测试.这是默认设置,但实际上并非全部.

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

当我在目录上运行上述命令时,我注意到Nose跳过了可执行文件.如果这是您的问题,则需要将文件模式更改为不可执行.在Mac OS X或Linux上,可以通过以下方式完成:

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

或类似的

如果您知道自己的模块/文件是导入安全的,则可以使用--exe选项运行Nose以在可执行的python模块中查找测试"(来自`mannasesttests):

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

这篇关于使用鼻子在目录中运行所有测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆