Is this the normal behavior of nosetests to pick only none executable .py?

有些话、适合烂在心里 提交于 2021-02-08 06:37:49

问题


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?

Tree structure of the project:

├── __init__.py
├── lib
│   ├── add_quiz.py
│   ├── __init__.py
│   └── take_quiz.py
├── README
├── setup.py
└── tests
    ├── add_quiz_test.py
    ├── __init__.py
    ├── testCases
    └── testData

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

回答1:


This is expected, but there you can use the --exe flag to collect tests from executable files:

It is important to note that the default behavior of nose is to not include tests from files which are executable. To include tests from such files, remove their executable bit or use the –exe flag (see ‘Options’ section below).

Here's the reasoning, from lower on that same page:

Normal behavior is to exclude executable modules, since they may not be import-safe



来源:https://stackoverflow.com/questions/34781207/is-this-the-normal-behavior-of-nosetests-to-pick-only-none-executable-py

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!