# help running unit tests against single test method

**URL:** <https://forum.ansible.com/t/help-running-unit-tests-against-single-test-method/20561>\
**Category:** Ansible Developer\
**Created:** [February 12, 2016, 2:35pm UTC](https://forum.ansible.com/t/help-running-unit-tests-against-single-test-method/20561 "2016-02-12T14:35:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kesten\_Broughton2](https://avatars.discourse-cdn.com/v4/letter/k/ecc23a/32.png) [@Kesten\_Broughton2](https://forum.ansible.com/u/Kesten_Broughton2)\
**Post date:** [February 12, 2016, 2:35pm UTC](https://forum.ansible.com/t/help-running-unit-tests-against-single-test-method/20561/1 "2016-02-12T14:35:21Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [February 12, 2016, 3:43pm UTC](https://forum.ansible.com/t/help-running-unit-tests-against-single-test-method/20561/2 "2016-02-12T15:43:44Z")

</div>

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
