问题描述
这是否是鼻子测试仅选择不可执行的 .py 的正常行为?是否有其他方法可以设置鼻子测试以获取测试目录中的所有 .py?
Is this the normal behavior of nosetests to pick only none executable .py?Is there any alternatives to setup nosetests to pickup all .py in tests directory?
项目的树结构:
├── __init__.py
├── lib
│ ├── add_quiz.py
│ ├── __init__.py
│ └── take_quiz.py
├── README
├── setup.py
└── tests
├── add_quiz_test.py
├── __init__.py
├── testCases
└── testData
将权限设置为不可执行,并且nosetests正确拾取测试
Set permission as not executable, and the nosetests pickup the tests correctly
[gliang@www quiz]$ chmod oug-x tests/add_quiz_test.py
[gliang@www quiz]$ nosetests -v -v -w .
nose.config: INFO: Set working dir to /home/gliang/work/prima/quiz
nose.config: INFO: Working directory /home/gliang/work/prima/quiz is a package; adding to sys.path
nose.selector: INFO: /home/gliang/work/prima/quiz/lib/add_quiz.py is executable; skipped
nose.selector: INFO: /home/gliang/work/prima/quiz/lib/take_quiz.py is executable; skipped
test1 (quiz.tests.add_quiz_test.add_quizTest) ... ok
test2 (quiz.tests.add_quiz_test.add_quizTest) ... ok
----------------------------------------------------------------------
Ran 2 tests in 0.001s
OK
当我将权限设置为可执行时不会
Not when I set permission as executable
[gliang@www quiz]$ chmod oug+x tests/add_quiz_test.py
[gliang@www quiz]$ nosetests -v -v -w .
nose.config: INFO: Set working dir to /home/gliang/work/prima/quiz
nose.config: INFO: Working directory /home/gliang/work/prima/quiz is a package; adding to sys.path
nose.selector: INFO: /home/gliang/work/prima/quiz/lib/add_quiz.py is executable; skipped
nose.selector: INFO: /home/gliang/work/prima/quiz/lib/take_quiz.py is executable; skipped
nose.selector: INFO: /home/gliang/work/prima/quiz/tests/add_quiz_test.py is executable; skipped
----------------------------------------------------------------------
Ran 0 tests in 0.000s
OK
推荐答案
这是意料之中的,但您可以使用 --exe
标志从可执行文件中收集测试:
This is expected, but there you can use the --exe
flag to collect tests from executable files:
需要注意的是,nose 的默认行为是不包含来自可执行文件的测试.要包含来自此类文件的测试,请删除它们的可执行位或使用 –exe 标志(请参阅下面的选项"部分).
这是同一页面下方的推理:
Here's the reasoning, from lower on that same page:
正常行为是排除可执行模块,因为它们可能不是导入安全的
这篇关于这是nosetests 只选择没有可执行文件.py 的正常行为吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!