问题
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