help running unit tests against single test method

I’m trying to add a unit test and while developing I only want to run against a single interpreter and only my new test.

Following the googles, i’ve tried a number of variations to run just my test. Can someone help me out?

Run from the top-level ansible directory.

tox -e py26 – test/units/executor/test_playbook_fast_fail.TestPlaybookFastFail.test_playbook_executor__any_errors_fatal_with_unreachable_host

586 tox -e py26 – test/units/executor/test_playbook_fast_fail.test_playbook_executor__any_errors_fatal_with_unreachable_host

GLOB sdist-make: /Users/kestenbroughton/projects/ansible/setup.py
py26 inst-nodeps: /Users/kestenbroughton/projects/ansible/.tox/dist/ansible-2.1.0.zip
py26 installed: DEPRECATION: Python 2.6 is no longer supported by the Python core team, please upgrade your Python. A future version of pip will drop support for Python 2.6,ansible==2.1.0,argparse==1.4.0,coverage==4.0.3,coveralls==1.1,docopt==0.6.2,ecdsa==0.13,Jinja2==2.8,linecache2==1.0.0,MarkupSafe==0.23,mock==1.0.1,nose==1.3.7,paramiko==1.16.0,passlib==1.6.5,pycrypto==2.6.1,PyYAML==3.11,requests==2.9.1,six==1.10.0,traceback2==1.4.0,unittest2==1.1.0,wheel==0.29.0
py26 runtests: PYTHONHASHSEED=‘1122456432’
py26 runtests: commands[0] | python --version
Python 2.6.9
py26 runtests: commands[1] | python -m compileall -fq -x test|samples|contrib/inventory/vagrant.py lib test contrib
py26 runtests: commands[2] | make tests
PYTHONPATH=./lib nosetests -d -w test/units -v --with-coverage --cover-package=ansible --cover-branches
test_basic_error (units.errors.test_errors.TestErrors) … ok
test_basic_unicode_error (units.errors.test_errors.TestErrors) … ok
test_error_with_object (units.errors.test_errors.TestErrors) … ok
test_get_error_lines_from_file (units.errors.test_errors.TestErrors) … ok
test_play_iterator (units.executor.test_play_iterator.TestPlayIterator) … ERROR
test_playbook_executor__get_serialized_batches (units.executor.test_playbook_executor.TestPlayIterator) … ok
test_playbook_executor__any_errors_fatal_with_unreachable_host (units.executor.test_playbook_fast_fail.TestPlayIterator) … ERROR
test_task_executor_execute (units.executor.test_task_executor.TestTaskExecutor) … ok
test_task_executor_get_loop_items (units.executor.test_task_executor.TestTaskExecutor) … ok
test_task_executor_init (units.executor.test_task_executor.TestTaskExecutor) … ok
test_task_executor_poll_async_result (units.executor.test_task_executor.TestTaskExecutor)

I always see all tests being run. I’m expecting only output for my test.

The problem, is that tox runs make tests, so having it prepend the path to the test doesn’t do anything. Looking at the Makefile, the only var you can configure is NOSETESTS, and we can overload this, such as:

NOSETESTS=‘nosetests test/units/executor/test_playbook_fast_fail.py:TestPlaybookFastFail.test_playbook_executor__any_errors_fatal_with_unreachable_host’ make tests

Also notice that I changed your test path. I added .py onto the file, and separated the file and the class/method with a :.

The other option is to run nosetests directly such as:

PYTHONPATH=./lib nosetests -d -w test/units -v --with-coverage --cover-package=ansible --cover-branches test/units/executor/test_playbook_fast_fail.py:TestPlaybookFastFail.test_playbook_executor__any_errors_fatal_with_unreachable_host